CT45514

The corridors at Lodebarrow

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The surveyor Notary has been asked to outscore the rival chapter. On the desk lies a long table of corridors readings. 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 <= 3289; the input is a connected tree.

Example 1:

Input: 3126 571 1822 28 3086 2339 2594 1502 1701 390 1817 2062 3077 784 1808 698 1005 275 401 569 862 881 2265 934 1699 350 1329 7 1323 1481 1837 1413 2259 553 797 19 125 68 382 218 640 1633 2425 40 761 489 627 55 774 1165 2906 1114 1367 31 278 1128 1655 1966 2833 902 2461 192 793 884 1477 79 615 925 1443 128 348 725 939 68 3113 117 1105 1556 2892 5 41 1992 2134 1654 2284 1243 1675 1144 2655 7 122 2036 2094 223 345 619 1991 6 1227 145 674 703 1792 1556 1919 1396 1944 919 2313 1428 1888 1010 2305 623 652 596 642 2692 2764 365 585 925 1987 2189 2346 2188 2294 667 2914 577 2009 256 331 102 565 2011 2862 247 825 189 266 587 2465 7 2401 332 1902 409 1182 973 2386 1042 1071 428 1877 308 1281 79 1543 191 1692 125 1075 399 663 2253 3094 154 1106 1250 2020 347 2596 664 2562 195 462 1270 1374 1193 2801 392…
Output: 35

Example 2:

Input: 251 172 186 10 32 128 181 1 19 4 6 27 52 7 99 11 115 53 198 4 43 38 80 125 182 2 125 86 142 38 200 97 147 3 4 23 54 132 183 2 3 33 201 30 91 98 215 79 173 65 101 19 36 8 15 234 250 2 62 6 50 45 51 17 26 8 92 5 12 195 207 6 169 4 8 132 238 149 157 39 111 2 14 6 83 140 167 55 151 23 64 143 249 27 163 52 68 93 211 190 236 23 29 141 143 84 138 65 149 120 159 35 87 19 33 8 203 23 228 81 217 40 88 45 220 71 123 77 247 72 139 173 246 61 185 175 176 97 107 2 21 6 37 25 218 45 94 26 112 141 233 37 70 127 232 1 2 138 165 30 39 104 189 19 242 7 22 148 195 43 74 88 141 151 180 42 71 36 150 55 118 59 214 18 24 184 212 16 34 206 213 20 102 49 79 30 85 28 140 8 23 235 240 64 134 47 222 32 191 177 184 129 152 26 170 6 42 168 171 97 128 18 205 87 96 163 251 27 93 13 162 92 230 15 72 205 239 155 210 88 133 …
Output: 22

Example 3:

Input: 2609 1643 1984 318 2222 472 1032 20 91 121 1828 156 833 440 1026 69 722 991 1823 790 887 93 124 870 1244 1657 1945 548 983 511 2003 287 2143 1773 1880 638 1076 1835 2336 201 1872 63 106 1117 1259 190 763 107 121 138 772 74 1346 907 923 251 512 16 497 146 230 874 985 1110 1402 724 1143 253 575 586 1807 85 1785 1149 1899 802 1017 102 1833 781 2508 1244 1825 58 1254 618 1581 883 2475 579 1601 207 1595 199 2303 1078 1956 267 491 798 1992 1435 2223 1418 1560 194 1685 1789 2452 344 733 321 744 351 735 511 745 325 580 89 1482 870 1730 226 588 841 1352 1431 2342 284 2024 323 1348 305 446 410 2458 1073 1161 200 1834 694 2352 500 542 1238 1363 542 617 369 960 697 2013 599 2466 1381 1417 933 1986 453 564 788 1365 56 318 83 202 1591 2113 1341 1894 273 1490 20 56 794 872 18 44 630 715 919 1284 494 2037…
Output: 30

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The corridors at Lodebarrow - MEDIUM Coding Problem | CodeTikki