CT40632

The Golden Longest Trail

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the frontier camp of Duskwood close for winter, Aria must finish the corridors 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 <= 3425; the input is a connected tree.

Example 1:

Input: 3113 714 1230 909 1689 1125 1409 256 372 1367 1833 324 967 237 2092 155 1511 228 606 61 1245 74 75 818 1143 513 1766 972 2923 131 1876 729 893 1235 1885 1907 3067 484 1509 1722 2892 6 127 445 817 50 2261 580 2771 374 387 30 905 167 585 142 955 202 338 2280 3063 1385 2979 435 597 1313 1491 808 833 16 17 1342 2242 530 2684 428 979 1058 2446 568 645 2099 2821 335 1258 1243 2604 54 170 559 1751 306 586 199 925 132 1931 774 1115 7 265 820 2372 191 2929 61 294 295 1461 1007 2325 3 260 428 2970 69 2152 272 747 1772 1999 1466 2133 384 421 836 1616 1900 2818 742 1135 104 355 374 1361 313 1178 160 2084 2664 2792 431 2270 95 779 89 1411 190 1290 2103 2349 90 840 573 590 102 2177 455 546 362 841 1188 1700 1823 2868 231 1345 316 570 933 1904 240 2558 675 1565 472 1080 631 916 1796 2559 1239 1413 2529 3…
Output: 29

Example 2:

Input: 1768 837 1029 206 930 490 1491 621 1440 31 64 196 979 189 365 395 818 872 1603 915 1080 128 1592 6 9 700 794 128 977 489 1428 76 110 798 875 347 363 471 1443 283 417 186 707 661 1547 1327 1733 832 966 912 1687 1296 1520 920 1674 38 114 906 1459 257 317 375 1008 379 449 15 285 469 950 57 235 612 846 58 644 200 217 373 988 555 1201 46 786 584 889 473 933 6 13 184 398 15 1019 32 288 842 1711 341 968 372 700 34 515 492 1677 729 1289 13 426 694 1622 1065 1644 98 349 6 535 689 1084 415 1667 421 1712 1088 1107 159 992 138 409 103 1544 350 796 542 867 122 1642 522 832 255 1252 38 54 398 1129 868 1041 230 1572 418 448 171 370 64 451 700 905 1073 1686 290 299 936 1207 408 631 451 498 108 172 664 734 24 946 617 677 270 331 1049 1427 822 1387 153 470 1106 1378 1183 1388 319 737 398 663 27 132 369 925 …
Output: 30

Example 3:

Input: 3011 1642 1703 639 772 1099 1443 301 2508 304 1132 533 1212 97 498 548 1303 982 2148 1584 1676 271 586 172 455 1360 1538 1644 2709 1062 2087 303 2135 32 147 1586 2094 966 1885 22 365 290 399 224 1470 902 1186 1023 1133 552 1000 1042 1143 2127 2590 850 1522 69 2602 1077 2099 383 2515 28 374 482 1009 177 2335 1112 2983 1239 2100 389 406 474 505 300 537 2 699 974 2662 170 2151 128 411 411 1627 98 163 1110 2360 1473 2246 669 1913 157 392 79 130 626 659 499 622 1709 2424 1671 2429 1746 2389 233 1588 656 1798 1079 1142 2147 2327 318 1266 286 2869 1023 1659 162 1299 363 822 838 2368 343 507 48 85 1613 2033 338 613 523 2073 2426 2888 894 2568 982 1707 460 884 261 468 1256 1368 273 333 1372 2152 944 2760 1096 1122 743 2790 1296 2721 1316 2048 1322 2754 2653 2921 761 1574 302 1486 5 20 484 963 90 45…
Output: 30

Constraints:

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

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