CT41836

Warden and the Longest Trail

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the clockwork quarter of Gearford pays by the answer, and Warden intends to earn it. First: the full register of tunnels. 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 <= 3049; the input is a connected tree.

Example 1:

Input: 2322 379 1206 90 874 726 878 580 1094 745 1327 140 214 130 663 136 997 127 250 1042 2162 893 1449 625 1170 33 46 7 56 1847 2232 513 728 1152 2003 7 178 120 305 814 1229 218 569 441 2310 805 1535 798 867 374 1737 1352 1419 75 134 718 909 1491 1769 48 616 1232 2123 510 777 432 1128 7 26 1220 2308 1061 1104 524 780 626 682 521 2291 213 341 1056 1542 30 477 93 348 408 947 276 1501 162 1091 1765 2255 838 2009 523 747 525 1974 259 1481 392 400 700 2029 561 926 583 1657 890 1349 380 2282 1341 1823 1713 2045 1346 1511 1030 1590 15 488 23 39 113 552 646 691 698 851 155 253 32 566 51 88 72 131 325 592 119 848 586 1585 2094 2208 19 698 85 165 502 2299 4 9 408 625 401 567 285 306 1776 2277 1106 1683 1733 2182 285 1284 173 618 76 895 582 1487 2038 2297 1083 1240 508 971 1029 1114 153 945 13 16 843 2020…
Output: 31

Example 2:

Input: 2885 2345 2618 1116 1562 454 966 492 2043 190 1390 585 667 2094 2754 1663 2183 700 2863 1441 1560 930 2056 1079 2462 592 636 876 1281 1046 1849 155 542 752 2349 423 701 118 229 1121 1227 1893 1960 328 1365 809 1273 17 2121 752 2097 1354 2063 585 1196 425 672 254 1968 89 577 723 808 1002 1985 822 916 328 1473 1151 2230 1810 2695 1601 2817 368 637 384 2356 855 1978 3 4 114 164 371 1169 185 403 711 2617 1906 2248 610 1579 79 198 178 294 506 992 131 540 128 1705 1163 2590 950 1143 1097 1325 1097 1678 349 659 2378 2788 1231 1405 153 159 281 341 995 2018 175 1210 1786 1894 13 2658 594 1148 2259 2734 38 1652 151 1700 92 1659 2738 2872 94 214 1364 2440 12 337 283 1230 18 1938 376 2471 280 2324 243 258 22 1537 695 844 165 428 130 495 437 558 460 2878 1026 2625 392 2088 167 325 1437 2355 303 763 113…
Output: 32

Example 3:

Input: 1272 58 731 361 486 60 447 25 787 276 300 40 499 671 1151 291 498 837 1115 4 365 13 665 488 527 396 1067 467 980 180 935 286 530 631 1225 63 116 775 838 168 1167 123 624 180 708 398 491 231 254 172 238 572 590 110 184 348 835 375 468 432 910 100 865 57 66 196 444 955 1038 135 658 420 1219 615 1098 97 232 36 301 260 932 539 1143 150 1177 136 1059 372 1136 128 755 345 1064 177 495 605 867 259 272 107 861 218 1214 36 928 18 497 49 1266 140 922 645 808 232 1132 109 676 229 312 82 183 272 1087 197 747 837 1157 945 1031 987 1084 26 1160 415 592 646 1096 195 253 6 10 342 510 737 959 150 622 508 805 519 1106 117 307 368 432 266 759 15 61 608 1027 526 775 1058 1216 696 859 47 78 18 43 243 335 9 72 308 430 258 488 655 705 534 885 103 1070 123 485 185 1039 117 704 256 972 526 1075 575 627 193 585 33 …
Output: 28

Constraints:

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

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