CT36354

Hugo's Ledger of tunnels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Hugo inherited the kitchen at the basalt cliffs of Obsidian Shore 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 <= 3908; the input is a connected tree.

Example 1:

Input: 3488 1516 2750 700 1715 108 228 369 1697 2060 2673 49 664 1187 1359 102 125 626 772 661 2466 53 650 1251 1314 1447 2318 613 2796 1222 1993 726 1219 23 2631 92 809 905 3413 939 1147 44 86 158 171 341 2568 148 2812 356 3325 611 900 2330 3387 1348 1518 7 2802 2094 2326 1141 3397 2160 2706 279 1380 966 1131 1544 2334 705 747 157 2065 752 1476 1571 3414 1422 2014 1113 1245 1346 2995 924 1342 245 475 51 105 1217 2929 1087 2758 1000 1003 393 538 134 459 472 2893 1705 2581 1693 2932 975 2514 377 1016 480 690 1168 1429 90 945 878 964 2077 2171 336 1704 790 1056 1476 2141 726 1338 491 692 643 700 663 1023 2384 3486 301 750 1106 3345 665 1100 348 990 2586 2657 403 840 116 316 833 2134 2008 2249 986 1998 2547 2549 1500 1795 110 825 993 1484 165 360 375 1139 237 646 482 600 1444 1456 970 1630 20 2464 7…
Output: 36

Example 2:

Input: 2429 690 1959 686 1532 90 396 662 1298 440 2233 378 668 1579 1758 912 1296 376 393 42 62 482 1072 118 145 546 1536 59 412 479 1308 88 845 147 180 189 1041 299 851 813 1347 730 1022 16 737 143 2309 81 242 658 1568 1233 1746 1727 2148 983 1573 1820 1868 2247 2423 126 876 247 468 4 2099 107 134 307 2078 35 1934 1323 1670 1443 1888 657 835 277 1915 733 801 211 529 67 2326 1123 2071 1410 2350 287 879 1659 1916 174 1769 428 1103 1859 2118 168 572 1449 2332 906 1732 650 1597 85 1395 159 751 67 397 245 1006 38 338 28 121 252 1501 181 1786 44 1957 99 2288 925 1421 1720 2130 341 631 849 1739 267 662 1162 1814 703 1032 1036 1105 906 2089 1051 1330 1201 1795 219 2329 173 1051 109 168 124 568 646 1361 189 602 572 773 410 669 160 249 428 496 1019 2305 161 254 378 956 89 653 830 1401 159 906 26 661 1217 …
Output: 32

Example 3:

Input: 2768 2117 2252 608 2359 2184 2734 70 1548 256 384 553 2204 469 978 3 856 364 787 250 1117 713 1623 596 661 795 945 79 333 881 950 221 238 1339 1467 1043 2661 1376 2258 726 2760 235 2500 411 675 484 2309 159 1540 632 2390 950 2512 283 2614 339 1887 1056 1351 592 1600 925 2148 236 583 64 1180 197 2732 88 258 738 2146 116 208 94 497 40 206 1957 2128 549 1506 227 587 1349 1406 2357 2466 284 1015 444 1067 502 596 955 1245 743 1143 1302 1692 94 2482 29 1501 106 1000 1380 1460 106 1465 282 534 255 1881 177 779 1501 1954 54 115 1119 2110 1071 2573 334 1702 572 1785 9 12 11 210 62 82 1525 1570 1894 2399 18 242 759 1277 725 735 53 119 26 54 10 2111 1458 2487 873 1873 1497 2053 1720 2581 300 611 98 889 2242 2429 2231 2302 48 2506 320 1188 1069 2657 554 1936 1510 1782 1393 2711 214 662 198 767 1384 19…
Output: 31

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Hugo's Ledger of tunnels - MEDIUM Coding Problem | CodeTikki