CT42710

The canals at Sleekwater

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the otter slides of Sleekwater, someone must optimize the storeroom layout. This year the task falls to Sara, armed only with the canals register. 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 <= 1830; the input is a connected tree.

Example 1:

Input: 769 48 515 196 464 162 539 262 596 138 286 52 133 446 511 118 333 38 258 47 50 88 109 7 604 121 522 123 747 385 503 141 185 45 71 453 560 80 138 576 703 69 599 12 656 4 9 214 524 268 394 14 153 397 585 170 188 22 143 31 190 281 764 50 332 93 97 124 158 69 142 206 396 431 683 401 476 15 88 230 642 6 31 456 564 1 4 6 12 170 340 65 122 249 361 407 713 286 487 53 125 4 337 356 428 469 508 138 323 65 92 6 191 378 409 33 542 71 393 58 118 133 169 77 268 64 553 399 750 118 235 57 469 11 673 7 25 171 700 19 98 247 528 190 754 516 648 357 386 253 677 17 85 45 759 147 653 56 156 26 303 36 91 307 595 709 732 111 315 336 756 120 557 57 189 152 273 288 348 591 614 417 540 76 171 249 588 79 398 521 609 181 459 9 54 466 616 68 103 560 635 318 717 282 325 46 74 169 665 79 260 598 686 546 743 252 279 272 4…
Output: 23

Example 2:

Input: 1769 1194 1477 767 1341 8 27 524 1553 145 653 367 779 11 811 254 386 371 718 455 588 169 293 760 1015 855 1102 100 153 16 70 1044 1220 32 587 29 60 422 874 410 443 302 492 735 770 479 1089 218 986 46 299 309 810 170 1219 510 584 84 415 1033 1043 970 1651 605 678 826 1104 486 1509 42 707 1 3 760 1356 613 709 758 976 36 217 936 1337 20 34 40 1515 676 1094 5 7 411 639 1397 1649 52 1436 404 719 203 1516 937 1353 84 585 400 954 120 419 128 995 714 979 831 1032 145 598 328 1626 9 47 371 1507 132 758 46 154 281 357 241 418 426 1493 307 1003 41 58 171 1197 26 326 179 193 925 1200 93 655 152 424 66 1279 106 354 56 101 234 603 841 1334 463 1607 816 1138 18 787 9 463 27 235 880 1438 401 1232 726 936 609 1459 913 1004 1032 1567 51 68 178 441 30 126 66 366 643 1299 202 260 666 1604 52 321 212 372 237 4…
Output: 29

Example 3:

Input: 736 157 461 77 184 126 199 505 710 61 436 136 157 214 627 72 317 140 271 162 612 47 131 5 725 233 287 13 437 8 375 69 482 474 706 154 269 488 591 240 471 4 11 71 585 24 419 16 108 25 144 463 498 120 647 192 221 429 551 211 632 166 370 2 254 569 641 264 307 194 203 20 235 96 164 426 645 123 257 69 78 412 536 125 133 155 583 80 240 239 361 160 484 29 651 546 557 382 449 476 497 425 669 166 579 181 274 325 399 199 542 20 206 426 511 146 649 384 611 33 58 356 506 133 296 99 428 291 418 28 89 8 92 58 232 69 155 56 276 457 539 13 15 144 237 18 45 344 426 356 619 102 504 241 734 20 95 97 586 106 599 230 387 274 700 486 507 635 653 147 381 24 462 164 341 10 500 77 80 336 604 215 519 314 420 442 487 62 84 50 181 131 247 394 663 301 699 14 371 207 584 137 463 164 319 425 502 603 735 109 173 381 537 …
Output: 24

Constraints:

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

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