CT55642

Surveyor Counts the tunnels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the willow walks of Reedmarsh, Surveyor studies rows of tunnels entries. One clean number will settle the guild's oldest argument. 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 <= 3891; the input is a connected tree.

Example 1:

Input: 2525 1398 1591 1931 1980 331 521 298 719 1592 2322 1413 1662 343 1860 267 885 1412 2446 3 1057 1163 1370 257 338 719 2055 165 273 1569 1939 478 1194 1666 1905 199 432 98 810 855 2165 2031 2097 645 968 806 1659 228 2257 156 489 66 239 36 480 57 411 2360 2435 108 924 382 851 760 1005 140 972 312 887 1151 2404 1303 1846 129 997 415 1973 903 1826 103 1477 39 58 114 193 192 1884 1658 1663 319 445 1862 1987 467 2515 653 1567 1254 1692 920 1605 678 2051 262 1592 1939 2448 1066 2265 406 1893 726 1412 82 529 468 483 357 1468 285 740 183 248 966 1041 383 732 13 298 68 2093 1748 1783 560 561 675 852 294 508 43 578 922 1653 524 1161 1865 2452 1896 2475 298 2378 357 1011 902 1928 250 284 211 414 28 1212 277 292 74 274 851 1553 377 383 802 891 1917 2226 9 13 47 582 525 1375 275 586 1324 1381 695 1024 16…
Output: 30

Example 2:

Input: 3869 199 3228 1611 2750 42 104 2316 3050 1667 1970 322 1506 1310 2316 15 67 856 2604 662 2387 811 1695 2619 3748 662 685 211 514 293 2271 742 2321 110 297 1889 3085 911 3435 260 1583 273 838 5 3152 430 963 353 991 1527 1857 352 665 793 2199 462 498 5 9 344 3214 166 2498 205 451 1577 2460 1002 1548 1718 1775 144 1218 1081 2739 1278 3378 144 648 70 1137 10 261 1044 3329 299 1996 632 848 664 1735 119 1524 21 172 624 746 2041 3291 3193 3595 1153 2174 30 41 878 2919 1600 1820 37 62 2968 3427 970 1315 3083 3225 244 327 1425 1711 1308 2706 305 321 576 792 231 316 1316 2790 313 1390 1 1205 621 2288 1917 2432 30 143 582 1357 2522 3464 1872 1927 221 542 1517 2183 2813 3381 2399 2870 599 801 1758 2057 2142 3628 1623 2656 117 850 1064 2994 302 566 81 410 1169 2421 1372 3424 481 591 55 181 2463 3382 59…
Output: 30

Example 3:

Input: 1696 33 1102 294 648 422 605 1214 1333 507 687 93 110 377 560 73 313 91 1205 259 489 340 923 330 1580 335 770 350 1223 1067 1450 1320 1399 260 311 562 752 577 1382 1037 1149 207 516 474 856 256 503 463 1257 3 1049 345 1327 778 1635 7 28 211 213 367 375 88 118 175 283 719 832 27 948 8 204 184 1222 657 1579 113 1633 171 195 231 1225 317 871 553 1219 713 834 62 692 944 1675 240 1298 384 1273 141 768 1196 1469 825 1379 338 1113 8 442 532 967 694 796 133 1051 1125 1659 70 1032 210 597 560 1134 1041 1413 596 1256 269 1529 231 858 1104 1397 380 717 982 1081 381 1203 13 98 695 1493 540 930 675 986 1155 1239 726 1296 212 1628 153 189 525 1146 291 903 40 841 639 1517 4 81 859 911 472 1495 527 1353 233 1365 22 47 130 1359 29 366 337 426 1155 1275 333 579 5 59 170 223 16 92 408 1044 154 666 159 565 44…
Output: 25

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Surveyor Counts the tunnels - MEDIUM Coding Problem | CodeTikki