CT46482

Bright bridges Longest Trail

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the northern keep of Frostgate, Cobbler the assayer keeps careful count of the bridges. settle the inheritance fairly, every figure matters. 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 <= 3384; the input is a connected tree.

Example 1:

Input: 2277 58 1733 235 1771 1234 1518 489 901 1549 1894 376 2243 15 1172 172 846 192 253 50 214 51 1804 914 1389 580 1090 74 837 497 2148 845 1403 545 733 1397 1726 190 2091 9 11 65 1627 950 1109 235 874 23 83 908 1215 355 445 276 1381 1533 2164 194 522 243 527 1637 2046 331 455 273 434 122 299 1095 1387 88 150 1336 1674 44 193 959 1497 231 1088 1556 1710 373 1185 140 1696 96 222 874 1519 1770 2270 960 1164 571 1644 101 546 158 1106 42 69 524 1220 804 1129 471 535 441 1049 2006 2139 774 963 185 504 927 1122 972 1845 94 1635 571 614 1270 1827 207 278 812 1785 103 852 23 1543 83 99 1695 2275 777 1369 1443 1746 106 163 101 169 102 1001 18 151 12 94 689 702 34 114 2087 2170 287 867 8 33 709 1807 702 1892 198 870 520 885 394 1489 230 553 1825 2047 1299 2240 18 23 194 208 1087 1342 1330 1762 919 1013 …
Output: 28

Example 2:

Input: 898 195 358 35 116 61 323 379 471 13 65 169 499 217 521 209 519 360 648 2 125 303 534 274 597 175 562 91 332 724 875 339 365 28 29 515 661 141 142 39 580 24 603 173 201 144 178 239 348 242 579 33 391 403 815 738 792 22 328 21 484 664 894 155 252 255 509 149 845 65 399 36 81 394 414 246 898 5 87 72 223 6 107 276 755 242 497 76 819 51 210 61 293 187 517 216 392 499 569 552 629 71 122 3 60 356 855 72 425 294 447 128 728 119 235 383 888 156 656 2 441 47 78 145 303 181 406 135 175 156 688 271 274 115 788 371 893 715 849 117 626 346 820 579 646 57 96 55 278 445 642 100 120 488 701 387 869 235 549 377 680 210 477 490 536 351 866 14 80 227 273 38 393 534 593 434 756 12 19 105 375 307 354 59 61 392 843 31 284 6 15 101 513 69 621 5 34 135 321 397 837 574 828 28 99 149 251 115 361 11 679 13 31 594 81…
Output: 28

Example 3:

Input: 2319 682 1719 151 2158 935 966 7 1223 42 112 1431 1623 1314 2266 1739 1956 746 2015 55 463 621 968 1368 2244 1553 2088 479 2004 1764 1851 673 1682 166 563 64 1517 29 1112 424 1013 15 75 654 879 222 1128 760 850 773 2314 404 685 864 1508 7 263 334 808 1064 1272 188 491 641 2206 838 1349 514 2046 56 88 1567 1936 1949 2290 58 579 20 718 432 989 978 1555 1312 1926 389 913 463 907 857 1842 116 1616 4 46 63 994 368 1808 13 1546 35 122 1019 1209 84 2020 133 1342 2089 2123 1522 1987 1474 2260 38 349 243 1227 752 2255 1053 2230 85 201 584 787 257 1243 208 1144 178 605 258 1007 434 1100 641 1275 34 954 1633 1913 811 949 1077 1605 427 467 4 28 699 1020 1161 1716 231 1131 199 372 240 872 562 898 1039 2171 475 1800 378 526 80 1585 1897 2061 2108 2318 885 1030 1507 2096 870 1368 66 571 1472 1522 29 58 4…
Output: 29

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Bright bridges Longest Trail - MEDIUM Coding Problem | CodeTikki