CT46022

The Longest Trail of Glowtide

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the lantern reef of Glowtide, Elowen records each bridges 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 <= 2228; the input is a connected tree.

Example 1:

Input: 1967 650 1707 283 286 1256 1560 588 1366 255 795 550 982 554 892 336 1240 277 338 638 993 1041 1336 341 466 432 687 1254 1850 502 771 171 742 335 1038 1247 1896 981 1106 4 74 28 753 522 1603 997 1856 11 76 297 822 62 1647 692 1045 396 729 384 1250 697 1601 23 91 856 1423 444 1539 419 427 315 450 499 1024 51 73 152 1061 990 1107 1260 1472 939 1815 1403 1508 1193 1744 1202 1354 529 990 196 1639 1111 1726 206 482 103 107 494 1600 703 1681 340 1005 165 715 43 1791 639 919 24 143 1265 1309 501 1590 827 1773 152 1931 747 1396 318 1873 822 1180 375 1820 91 695 816 1636 104 124 111 1059 7 145 48 247 223 1295 481 1536 89 1556 450 1143 413 814 20 137 65 710 1257 1368 104 116 331 911 258 478 896 1031 1008 1181 63 1211 84 99 1171 1721 17 187 1130 1753 427 667 835 1353 533 796 422 1481 404 413 74 589 7…
Output: 35

Example 2:

Input: 1582 78 707 823 1412 43 545 200 572 234 511 1014 1101 47 54 412 738 545 917 3 130 605 1390 17 18 143 530 432 975 985 1236 755 960 124 153 407 1140 1149 1336 633 1571 121 1248 5 350 750 1046 209 964 209 763 62 123 96 280 210 263 594 1324 86 425 38 741 149 361 619 1327 155 418 675 1092 386 953 85 167 137 185 460 622 310 411 216 377 483 1580 150 697 100 246 1381 1442 987 1551 30 220 239 952 78 954 250 1352 308 1527 203 661 188 1197 24 275 275 515 162 980 148 775 37 61 53 150 229 965 1419 1432 608 654 658 766 201 475 85 325 242 1347 519 709 293 328 242 873 718 894 918 1495 922 1119 340 1132 379 666 205 561 996 1193 886 1485 704 1035 585 769 263 521 16 81 402 656 355 995 228 948 1137 1358 942 1157 711 1549 779 851 1217 1535 5 152 713 799 295 1051 682 1015 209 723 54 955 138 376 181 235 137 823 …
Output: 26

Example 3:

Input: 2091 146 408 1259 1571 560 624 608 924 622 684 242 442 398 933 103 458 41 70 16 1222 102 612 47 110 133 1927 85 1084 458 733 729 1872 1028 1458 641 1100 628 657 58 1730 377 1358 65 128 665 1187 242 519 484 1798 150 329 684 1132 406 784 287 291 34 491 84 304 535 1324 576 1908 723 1221 1541 1902 620 918 344 507 1538 1804 481 1748 596 1154 195 353 345 1944 1405 1783 27 637 450 1115 439 1667 277 1244 55 443 582 607 388 1156 959 1723 771 1540 264 499 66 1477 1128 2051 632 1549 799 1146 1354 1552 856 1744 1387 2019 28 161 168 797 1275 1881 434 751 445 957 686 1996 422 553 138 1098 723 1834 487 1535 661 1069 363 1824 472 1511 637 950 944 1544 389 1485 503 717 139 1101 74 314 1035 1357 110 780 620 1185 564 1021 1650 2078 752 1888 925 1046 18 20 866 903 888 1786 1224 1942 531 1191 446 1235 609 1342…
Output: 30

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Longest Trail of Glowtide - MEDIUM Coding Problem | CodeTikki