CT50209

Gardener's Longest Trail Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the orchid house of Bloomglass close for winter, Gardener must finish the routes ledger - one figure at a time. 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 <= 3459; the input is a connected tree.

Example 1:

Input: 473 159 292 88 454 34 253 29 43 5 48 2 368 159 250 347 358 140 282 122 327 19 370 327 384 6 9 42 116 175 183 98 430 77 221 72 277 83 168 1 13 22 107 19 50 125 471 35 279 242 353 205 283 70 157 119 429 225 281 137 340 61 209 4 31 237 318 258 403 25 244 106 274 111 304 359 437 219 325 151 343 120 450 394 472 352 363 107 158 150 196 16 18 11 126 254 351 205 273 35 235 212 392 183 432 98 115 37 44 224 441 122 227 66 178 131 323 285 356 272 470 13 51 103 288 9 257 220 348 134 396 14 16 369 453 32 147 288 300 41 87 147 203 61 359 166 195 5 10 1 24 28 388 356 423 108 206 99 308 109 460 289 469 112 132 36 83 52 395 38 420 58 71 10 29 34 42 60 404 67 184 165 173 138 439 131 383 206 375 204 411 173 177 29 426 105 199 163 280 138 198 368 387 181 382 58 103 120 164 340 391 27 30 113 233 76 298 149 296…
Output: 24

Example 2:

Input: 2384 58 164 201 559 1902 2084 489 604 4 2194 1380 2216 196 1973 607 1947 1502 1577 413 1750 1515 1954 825 1209 322 1717 800 1331 42 53 426 1578 2 71 919 968 91 333 888 1590 227 677 497 947 1482 2356 601 1520 963 1014 1177 1808 356 574 1028 2263 103 171 192 751 80 175 476 689 595 1096 482 549 358 1749 10 116 1126 1594 82 605 333 2031 1429 2380 62 131 399 661 390 1334 816 989 128 705 41 81 709 1258 283 673 1548 1982 25 959 997 1974 140 731 27 2109 420 1781 340 502 1150 1453 1097 1288 71 954 455 1925 423 1160 830 2374 967 1029 113 1285 32 150 116 172 56 130 824 1256 83 884 566 1152 1126 1400 193 279 1608 1774 160 203 969 1662 460 535 1534 1609 1842 2105 855 1811 668 1228 969 1176 576 596 130 1216 1229 1546 1300 1678 448 1886 5 230 559 2338 422 1868 431 877 280 467 583 891 565 851 250 811 248 …
Output: 29

Example 3:

Input: 2160 241 541 200 792 882 1310 884 1676 484 922 12 105 681 1287 312 1695 1414 1616 1411 1424 238 1769 863 1120 796 2073 362 816 442 676 486 1558 63 360 933 1307 282 852 425 620 878 965 238 1233 1065 1839 415 990 447 1160 1027 1405 102 740 696 1421 587 649 156 186 1187 1522 707 1028 174 530 264 588 8 15 1266 1388 521 1822 230 1938 134 145 1899 1909 1275 1575 395 502 999 1746 380 460 121 1197 226 1089 544 1429 1378 1780 136 1022 55 71 88 335 879 1212 9 1527 46 496 657 1928 971 1382 1147 1737 747 927 1 2 119 1183 95 1060 1988 1997 378 961 590 1010 360 2032 765 1118 1028 1834 6 561 50 315 565 576 632 1571 58 81 257 1345 681 1171 1053 1450 767 2098 238 254 142 234 374 435 603 1157 253 624 172 800 122 143 557 1580 897 1448 1271 2111 1492 1763 474 552 186 1821 136 275 534 574 1320 1854 47 540 11 4…
Output: 30

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Gardener's Longest Trail Ledger - MEDIUM Coding Problem | CodeTikki