CT55869

The Greystone Longest Trail

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the shale slopes of Greystone; Neel weighs the day's tunnels 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 <= 3523; the input is a connected tree.

Example 1:

Input: 1157 14 83 25 35 71 609 3 11 266 589 728 1025 239 674 99 131 892 972 492 699 408 662 333 936 462 769 370 543 132 635 66 1042 189 816 837 1057 211 980 223 561 529 712 73 1151 70 229 234 526 824 859 236 1027 102 293 14 60 168 192 555 782 292 913 335 433 118 214 317 783 35 196 160 576 365 605 495 798 32 103 273 287 4 65 528 900 260 780 226 628 149 348 192 667 188 872 481 850 645 1149 89 157 182 431 64 82 118 271 231 430 995 1058 200 324 9 19 11 127 290 650 621 1143 427 566 573 577 197 514 300 849 88 252 847 961 578 740 10 53 97 926 33 175 109 408 1037 1063 186 852 435 1104 140 647 94 161 21 150 680 1044 437 736 95 353 627 636 88 954 817 1018 419 583 116 124 676 1040 65 871 663 703 91 137 421 434 24 501 137 228 164 352 743 858 363 384 760 1069 786 806 257 351 193 232 626 856 749 789 18 34 192 …
Output: 29

Example 2:

Input: 2151 38 400 75 1839 342 385 1483 1795 847 1721 107 127 123 527 354 807 38 1684 1083 1194 1071 1857 496 1220 164 692 281 1524 464 1746 298 787 743 1933 571 616 210 1646 442 624 1459 1879 1151 2018 8 11 13 1466 157 1841 977 1339 195 640 133 1010 181 1671 793 843 672 1033 769 916 366 711 230 561 131 163 27 93 296 943 1080 1832 1007 1377 9 870 57 79 707 1405 1297 1963 1414 1783 144 1515 1225 1819 109 868 979 1807 1780 1843 353 1388 214 317 220 614 327 2079 397 1675 922 2058 152 286 111 322 635 1306 1463 2057 13 1477 36 184 68 189 126 424 497 699 224 464 1530 1734 1053 1470 911 1931 434 1446 13 28 334 1653 208 839 441 1307 536 706 1002 1423 1037 1669 441 1816 411 925 532 805 620 672 1267 2002 529 574 16 544 1056 1156 31 89 25 167 1349 2130 143 146 54 353 1182 1246 11 14 924 2139 402 1585 769 17…
Output: 32

Example 3:

Input: 2126 1094 1580 460 1067 52 268 1541 1558 1309 1752 809 1858 1254 1873 1244 1496 196 1848 504 1633 667 675 1168 1594 88 179 63 1346 1256 1422 662 1152 260 1209 480 1169 166 803 899 1616 1479 2015 137 286 758 1295 1408 1657 744 828 1078 1084 40 1203 457 1344 152 160 352 2071 104 1541 211 310 422 528 8 494 519 521 117 373 19 1217 669 841 84 1871 943 1515 215 380 8 230 1520 1600 300 717 165 556 3 4 273 1430 385 759 596 1299 1921 2050 203 2055 540 2113 405 1714 734 1615 963 1122 967 1089 1228 1407 116 1816 577 965 286 359 309 318 177 1478 319 397 697 2024 1015 1367 445 570 1636 1772 205 863 133 1535 608 777 400 434 46 48 1296 1984 1114 1656 1661 1741 24 34 1108 1893 177 593 245 815 89 504 59 292 439 1315 1922 2073 18 444 478 772 26 330 20 35 113 180 201 322 233 636 566 1096 1339 1678 553 851 19…
Output: 28

Constraints:

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

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