CT39572

The Longest Trail at Vineward

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Navigator runs the signal tower at the ivy courts of Vineward. Today the books show a list of bridges, and the numbers must be worked out before sundown. 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 <= 1756; the input is a connected tree.

Example 1:

Input: 1064 81 92 263 754 850 987 5 16 56 229 10 82 66 126 277 278 101 177 290 761 404 677 698 1047 525 564 595 977 129 349 378 582 290 498 506 885 4 14 282 664 98 204 540 896 551 821 558 714 471 943 194 663 13 18 537 978 35 85 15 113 444 526 167 973 304 319 400 665 256 402 200 575 164 220 73 141 145 252 71 901 704 751 533 991 207 505 478 797 8 147 524 811 295 297 22 183 729 929 782 827 283 702 167 490 131 142 71 292 41 378 94 219 575 647 634 781 907 1059 111 114 569 944 388 1028 133 291 350 709 218 685 349 466 126 794 198 284 437 633 51 64 348 494 71 234 60 330 203 957 15 265 224 838 156 418 24 553 545 601 342 486 169 329 853 871 4 443 141 407 71 134 47 803 137 579 727 866 123 157 311 440 144 318 584 996 232 701 671 1015 4 602 227 428 270 346 459 540 285 360 679 786 396 403 76 584 403 626 344 77…
Output: 24

Example 2:

Input: 1491 133 1462 651 976 557 923 1078 1466 717 965 682 881 963 1127 55 602 871 1409 124 361 2 9 136 1247 526 675 1221 1259 257 1416 276 394 1079 1099 499 519 940 1033 39 316 822 1066 231 246 313 1146 41 956 145 1024 382 1356 285 568 387 509 374 641 836 1304 318 467 2 5 92 1403 335 837 261 306 198 1273 149 196 92 1011 240 514 378 1199 297 706 28 302 1115 1305 172 271 451 1287 150 817 5 26 492 899 198 320 464 472 288 1357 126 882 372 1110 556 688 804 829 935 994 502 1419 846 1451 725 1190 96 310 113 639 1195 1405 122 1168 243 273 29 156 27 646 253 331 28 100 24 44 139 898 62 518 175 1068 1261 1330 439 765 640 1354 34 91 92 916 502 524 24 1059 87 452 865 1406 6 131 60 457 587 699 21 23 32 1069 65 75 65 122 1054 1298 928 1352 713 735 737 988 192 1050 86 1279 437 486 6 10 688 990 534 1094 217 846 …
Output: 29

Example 3:

Input: 1340 588 789 412 463 599 619 328 405 1005 1245 92 296 77 407 1020 1024 166 639 667 1087 522 1149 190 236 119 486 384 784 528 1186 693 1314 146 1321 184 484 1025 1060 293 819 174 823 27 242 41 731 159 290 237 316 87 218 322 487 699 713 551 680 187 1040 113 347 352 1148 97 837 2 50 184 780 654 1142 93 1324 413 612 3 5 8 231 17 46 27 1059 117 930 928 1081 147 630 776 911 363 921 429 1225 18 23 1208 1220 420 530 19 194 27 72 17 209 455 623 888 927 746 871 669 957 535 709 263 399 167 553 221 565 40 52 20 542 208 363 92 488 16 166 840 1303 114 370 2 6 293 541 135 249 933 1108 180 944 124 1144 884 1190 43 472 63 123 57 369 373 940 331 356 796 1193 374 635 472 707 605 640 283 679 293 1075 122 774 321 684 3 42 116 216 45 359 38 904 382 431 173 186 746 1292 28 276 437 838 250 716 316 1185 313 477 37…
Output: 22

Constraints:

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

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