CT44280

Bishop and the Crystal tunnels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Bishop inherited the exchange at the lantern district of Glowfen along with its curious bookkeeping system for tunnels. Time to make sense of it. 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 <= 3398; the input is a connected tree.

Example 1:

Input: 3039 84 92 49 1982 954 2302 1903 2518 166 396 638 3003 17 169 1654 2090 310 748 1900 1906 330 595 875 1193 489 1445 23 2619 1470 2458 477 948 17 25 1124 1402 477 1487 790 954 502 2545 105 221 1256 1933 1839 2633 52 143 647 835 829 1128 1548 2297 101 301 227 1132 1599 2464 16 1756 1018 1232 644 1498 25 216 234 928 580 1512 45 71 978 2496 1508 2214 36 949 59 2643 234 3035 43 2911 770 2686 2287 2344 162 197 330 1524 1293 1761 1332 1654 2307 2978 955 2208 15 19 478 2489 790 2362 1384 1610 2331 2752 214 477 302 330 281 1403 1196 1491 94 532 729 2789 790 2586 2409 2647 161 1592 420 460 1174 2505 70 380 746 2783 2392 2567 2254 2879 1454 2566 154 2092 667 2665 45 187 169 807 296 426 718 2849 26 101 1096 1780 405 1667 1072 2166 446 670 1364 2195 36 219 1296 2070 2151 2995 1098 1497 793 2202 741 144…
Output: 31

Example 2:

Input: 2278 348 1151 571 902 1431 1493 618 1939 858 1214 802 2236 136 431 153 653 839 1506 588 1907 798 1756 272 732 148 320 215 2009 276 833 837 1615 177 1547 656 1671 1051 1203 614 2039 1970 2101 207 360 592 1899 73 1754 44 201 342 1075 197 429 1625 1923 351 849 1447 1565 188 644 99 256 532 1280 740 1858 459 831 1269 1413 1024 1978 157 377 11 263 999 1104 56 85 916 1850 31 255 578 968 1334 1911 461 765 275 1040 93 166 527 708 745 912 69 242 550 990 955 1970 57 189 989 1509 1026 1401 38 180 258 939 1285 1382 475 566 429 1912 1173 1441 506 1908 200 492 10 51 1011 1411 687 1001 502 1035 713 1377 858 1160 322 1379 640 821 113 127 13 191 475 477 1634 1843 185 725 505 1239 99 1995 550 1000 351 809 550 754 64 313 716 1350 11 39 48 519 360 1095 580 2179 352 366 142 2087 106 328 1 18 163 491 255 1588 36…
Output: 30

Example 3:

Input: 2557 53 395 531 1913 26 47 68 237 473 1711 648 1630 1159 1803 94 1019 269 710 93 1161 1289 1967 788 1309 33 443 599 2515 2042 2298 123 1562 455 473 1347 2081 260 348 799 1304 253 433 571 637 777 900 79 1584 937 1164 228 929 181 655 519 1216 84 98 389 2509 406 753 902 2031 50 436 203 513 17 36 26 1676 401 646 1565 2156 1167 2363 115 1200 344 498 24 1996 521 936 649 718 279 370 1572 1650 73 920 492 862 9 516 234 441 61 314 931 1392 753 2044 16 96 12 252 414 2314 1245 2357 2037 2552 73 299 618 823 37 197 1123 2095 138 1149 437 1888 1412 1510 446 799 745 1973 279 1254 667 918 1986 2139 2161 2185 970 1109 227 234 371 406 1486 2180 928 1212 500 807 1859 2505 83 145 647 1222 1154 2138 451 1279 241 1074 99 180 68 115 6 1278 994 1496 697 2181 180 269 496 1127 1094 1862 448 937 13 643 416 1402 1044 …
Output: 30

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Bishop and the Crystal tunnels - MEDIUM Coding Problem | CodeTikki