CT35870

The Timeworn routes of Mira

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Mira runs the chandlery at the ribbon falls of Cascade Vale. Today the books show a list of routes, and the numbers must be worked out before sundown. 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 <= 3912; the input is a connected tree.

Example 1:

Input: 2660 542 1039 1306 2115 45 54 376 787 182 1867 328 422 422 1266 620 1572 759 2060 448 685 579 694 1670 1678 199 1749 402 1042 37 543 1015 1324 158 177 406 2376 1495 1554 288 353 637 2102 909 1380 1455 2180 221 556 929 1885 273 2434 1381 1865 592 605 816 1185 2442 2570 2274 2614 405 1949 304 1246 7 508 845 1069 48 156 1854 2390 1116 1917 598 738 1029 1608 1580 1616 22 381 606 903 1710 2167 914 1052 149 160 796 1013 235 860 307 308 234 2613 855 2359 921 2510 237 307 586 1206 111 379 367 410 979 2340 596 2055 144 1751 632 925 86 230 150 318 972 1733 2378 2585 60 331 43 148 19 444 1678 2233 205 305 138 712 386 2543 427 1876 944 985 762 1294 357 366 230 804 1814 2519 105 246 201 802 1016 1319 385 810 1495 2271 70 143 437 1601 420 455 433 1237 438 887 531 612 552 1171 89 398 789 853 240 968 229 …
Output: 32

Example 2:

Input: 1378 786 1259 427 716 3 6 373 917 13 914 636 1019 7 192 81 602 3 19 129 918 65 246 393 482 47 447 697 1127 924 1038 648 898 531 974 692 913 379 924 354 411 528 1043 5 892 76 243 296 852 64 1132 282 331 630 685 192 971 93 1302 860 1227 82 120 154 1000 398 761 575 1049 845 1239 49 188 858 1371 458 548 1 7 313 1165 695 1002 83 86 94 183 841 1335 726 1144 559 1337 147 1050 151 253 352 834 4 323 230 496 332 491 1111 1321 56 114 57 130 476 513 940 1015 37 1292 10 51 199 439 306 489 12 694 756 1130 63 594 86 241 314 840 205 355 1005 1120 96 964 86 880 232 329 49 1178 91 1054 210 581 158 287 258 628 41 728 152 673 415 1155 556 573 112 256 119 428 5 66 63 154 262 335 656 762 344 1310 15 406 1182 1360 620 1338 359 538 343 961 223 505 66 123 152 607 136 197 40 260 441 960 587 851 532 998 23 298 637 1…
Output: 26

Example 3:

Input: 15 6 8 10 12 4 14 2 3 8 13 2 6 2 7 7 11 10 15 1 2 2 9 3 5 3 4 6 10
Output: 6

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Timeworn routes of Mira - MEDIUM Coding Problem | CodeTikki