CT49517

The Ivory roads of Boris

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the honeycomb cliffs of Beeswick, Boris records each roads in a worn leather ledger. The guild wants answers, not guesses. 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 <= 3701; the input is a connected tree.

Example 1:

Input: 2135 296 1836 208 250 890 1565 266 272 198 2061 971 1306 157 981 330 660 76 352 39 1420 487 964 87 332 295 444 894 1356 860 980 184 190 896 1350 136 492 902 1553 577 876 998 2078 1815 1997 1600 1965 100 757 1870 1915 565 645 1388 1878 499 1138 16 329 529 933 243 527 522 922 110 275 290 1545 125 254 30 67 30 236 106 624 120 1824 566 1533 169 328 339 575 17 815 26 311 194 198 977 1128 683 706 755 1261 224 542 66 143 617 1503 1015 1200 886 2110 1 2 424 2095 428 758 850 1954 1827 2045 46 211 440 545 1553 2119 1488 1617 4 7 28 30 273 1609 526 1220 1246 1838 610 1536 387 1094 174 231 38 748 1219 1314 130 246 723 1142 359 652 1144 1875 1 6 880 1524 646 1430 179 611 754 1983 52 56 538 739 214 1419 498 610 848 945 892 2112 42 538 1544 1738 39 183 1105 1586 145 586 1933 2101 453 761 300 1132 568 580…
Output: 30

Example 2:

Input: 2988 402 2112 263 1592 297 2191 14 511 2189 2520 1303 1454 24 90 715 2434 470 1740 140 418 1027 1100 1628 2702 2337 2410 299 793 2142 2928 889 2596 1807 2210 439 820 884 2032 483 1357 941 2123 445 653 410 2319 1383 1402 691 784 460 1246 309 501 701 1264 260 381 513 690 369 1609 179 209 1598 1965 136 575 762 1515 2409 2583 1571 2025 298 531 246 1077 47 95 952 2979 4 19 2539 2806 1259 2250 36 248 1218 2223 244 1202 428 2099 1249 1513 377 1195 547 631 1292 1812 784 2403 904 1224 131 564 419 456 515 1487 1630 1867 1620 2971 287 849 817 2506 87 280 743 1833 1824 1985 606 838 86 995 20 68 967 1266 257 496 732 1287 574 1128 352 805 50 1054 467 745 570 1162 532 2811 2050 2218 635 1315 514 1703 9 293 669 1034 34 272 2399 2871 31 390 1175 1292 596 1334 284 550 1324 1780 1930 2476 575 1109 1671 2845 …
Output: 29

Example 3:

Input: 177 9 97 70 102 84 152 29 126 9 57 93 157 53 87 88 164 49 98 128 137 16 18 33 95 10 174 48 85 18 42 122 146 24 89 9 13 70 78 2 8 16 23 71 129 10 17 110 163 7 10 1 3 20 112 69 108 55 59 25 49 30 158 34 71 34 46 95 110 5 33 164 170 38 106 15 61 19 173 23 144 37 168 67 70 64 145 31 171 4 27 7 30 64 90 13 139 18 24 46 124 22 60 107 128 1 26 57 69 9 37 43 73 21 36 13 66 51 155 4 7 24 62 2 5 7 14 37 48 41 111 1 15 10 107 79 86 51 65 61 135 15 51 66 93 54 142 2 4 132 140 53 56 15 22 17 75 26 47 9 20 52 67 128 175 60 74 12 83 33 40 80 143 3 6 43 79 61 151 71 104 20 31 87 114 15 105 40 41 23 153 37 147 8 21 51 84 44 55 94 138 62 88 33 94 102 149 28 32 70 109 7 117 3 25 42 141 76 154 33 43 103 119 120 161 59 81 3 9 110 122 25 38 17 127 13 150 124 131 14 103 4 92 28 121 25 68 2 45 5 16 144 176 96 100…
Output: 18

Constraints:

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

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