CT45286

The Longest Trail of Bluehollow

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the indigo vats of Bluehollow. Eklavya spreads the bridges records across the table and picks up a sharp pencil. Task: A tree has n nodes and n-1 unweighted edges. Print its diameter (in edges). Input format: First line: n. Next n-1 lines: u v. Output format: Print the diameter. Constraints: 1 <= n <= 1816; the input is a connected tree.

Example 1:

Input: 989 43 574 454 899 575 983 945 952 121 770 327 527 39 843 235 752 378 477 83 388 57 296 613 913 15 43 203 878 390 439 732 803 281 951 341 445 309 670 522 777 74 160 187 895 476 635 350 766 93 732 77 649 208 748 764 922 386 387 653 781 539 742 36 187 180 202 500 657 132 176 211 301 155 211 27 841 489 541 364 461 133 536 801 873 20 321 568 667 591 969 25 53 448 690 473 855 197 447 590 928 306 565 227 511 216 681 7 56 66 120 746 824 919 958 84 279 25 248 321 324 366 842 277 924 24 282 552 663 518 613 33 71 15 193 193 384 365 426 158 381 813 906 11 63 8 16 244 259 72 185 209 418 119 172 68 354 538 671 21 154 475 679 106 264 472 953 323 335 721 735 51 546 552 640 153 864 219 351 484 594 255 745 296 724 120 360 146 205 238 357 314 835 164 751 129 175 415 695 105 269 206 633 465 538 83 415 74 523…
Output: 24

Example 2:

Input: 767 434 505 33 170 60 193 118 141 560 594 199 666 46 48 57 711 46 79 31 57 11 18 2 39 261 431 452 474 185 399 209 385 109 136 593 677 101 140 534 645 108 330 8 33 285 519 414 712 151 295 291 582 180 397 318 572 30 427 267 597 22 99 350 549 126 696 23 134 78 118 4 5 398 525 385 463 326 342 260 379 355 523 170 265 73 217 44 369 368 717 3 234 152 251 14 283 75 256 58 722 166 571 191 605 347 728 141 148 519 704 345 670 342 362 552 750 18 31 7 133 584 598 236 238 143 230 36 37 40 92 192 273 154 335 270 442 85 640 27 40 264 416 20 126 214 258 56 64 59 108 47 343 202 739 230 293 441 706 121 491 282 500 7 9 519 579 217 621 59 98 335 410 245 409 238 270 6 196 58 132 357 451 522 566 202 753 135 541 325 371 111 488 353 665 377 524 112 122 17 224 133 172 309 332 630 725 497 575 50 84 396 467 294 393 1…
Output: 27

Example 3:

Input: 284 132 233 18 24 15 20 233 260 4 59 89 92 18 125 63 114 137 159 5 12 17 28 38 75 88 194 83 161 150 185 24 49 5 19 94 188 27 72 5 38 112 199 58 254 66 193 124 242 10 81 45 61 16 97 7 43 142 206 43 99 30 45 40 107 67 68 54 195 16 132 17 265 25 118 154 273 13 181 4 237 18 166 1 6 139 183 120 220 40 105 8 89 29 240 27 146 5 13 90 175 174 236 170 191 50 232 5 170 214 250 75 282 10 140 27 111 14 217 31 227 1 177 78 102 62 283 109 126 115 137 2 27 145 156 85 222 33 129 20 85 72 135 109 127 20 133 83 116 38 76 11 149 173 246 110 143 1 16 8 216 38 77 188 202 119 221 51 215 85 122 139 169 15 178 148 190 67 218 210 270 104 264 142 150 2 39 101 197 99 104 216 281 172 201 12 80 37 192 194 255 252 256 41 241 54 160 13 69 129 214 71 208 201 280 60 117 8 108 138 139 140 235 23 71 188 198 1 2 118 252 17 2…
Output: 20

Constraints:

1 <= n <= 1816; the input is a connected tree.

Loading...
Test Cases:No test cases
No test cases available.