CT50971

Ancient corridors Longest Trail

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the bamboo terraces of Verdantstep; Mina weighs the day's corridors manifests and starts the calculations. 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 <= 3853; the input is a connected tree.

Example 1:

Input: 2259 645 930 290 840 38 101 39 293 4 7 417 738 60 109 44 100 997 1341 165 655 10 83 267 507 626 1487 99 278 7 1573 94 105 83 1463 70 434 582 773 180 1956 278 888 442 591 315 1690 20 722 1169 1507 984 1186 1169 1842 1278 2047 159 1748 423 824 433 677 55 2192 76 320 155 1980 81 877 597 685 607 638 1281 1649 511 1305 551 740 455 2029 1460 1829 405 500 562 1818 43 155 1 288 156 2113 928 1041 1248 1476 347 876 1292 2015 14 1026 15 77 1312 1480 1375 1968 1696 1705 166 980 27 344 275 1031 68 113 1261 2227 1260 1410 983 1873 565 1389 301 441 289 783 75 851 73 249 1013 1257 992 1708 493 1494 174 330 593 1093 42 386 60 271 233 384 134 1072 910 1880 290 1861 245 1324 171 355 702 995 27 916 489 542 311 1069 1128 1344 53 446 891 1988 1713 2163 940 1617 494 1133 1026 1267 21 94 954 1000 514 643 454 678 …
Output: 30

Example 2:

Input: 3758 349 606 711 919 1137 2137 347 411 37 67 564 743 1137 3632 3223 3671 491 504 1907 3169 1279 2792 116 381 385 879 1043 1377 907 2189 663 1386 1022 2312 394 3505 1134 1146 485 1893 1524 2452 265 1145 1516 2688 1005 2658 1392 3462 9 238 792 1003 2185 3005 2103 2279 1296 2288 941 1641 160 242 1205 2674 530 670 489 2598 2493 3449 22 1008 148 475 734 1680 3236 3429 131 827 325 538 1042 1728 1128 1428 473 1172 710 826 1747 2693 52 323 269 741 2287 2765 485 1179 2606 3527 1503 2919 1824 2605 1748 2786 907 1400 2834 3047 135 463 827 1835 1738 2336 160 1245 1024 2475 443 2340 28 271 41 2695 591 2937 524 1448 480 974 110 263 517 580 2452 3243 818 960 1028 3035 2143 3747 1635 2833 2393 2878 390 687 387 951 413 1551 1549 1947 213 268 1702 1977 391 3281 2403 3605 271 401 1310 1346 581 1380 1160 1954…
Output: 30

Example 3:

Input: 3017 1168 1429 778 1859 199 409 159 1537 996 1809 23 837 633 2172 1342 2692 331 2973 442 1220 23 43 206 630 1173 2576 1738 2161 347 959 365 1535 531 2491 90 982 225 1201 501 1379 593 2373 521 1820 197 429 1163 2945 251 432 687 811 35 515 446 2980 493 1107 2075 2887 2802 3011 1520 2472 146 228 610 792 172 285 2 2522 2143 2804 872 1499 482 865 166 2999 532 1060 1101 2482 2211 2567 1638 1828 252 1899 213 1576 960 2437 699 1381 1342 1593 297 933 249 1205 1757 2994 612 2464 25 916 567 717 66 133 17 585 291 2562 950 2368 1411 1413 161 258 39 243 1068 1145 2424 2714 999 1639 429 2827 519 1049 1059 1876 576 1994 54 353 455 593 172 328 1807 2872 774 1952 1539 2751 1728 1823 151 1636 185 2852 465 1018 703 1951 453 839 594 2564 1059 2604 24 50 1800 2710 581 2917 76 238 2275 2447 580 2597 1077 1199 30…
Output: 30

Constraints:

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

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