CT39796

Farmer's bridges Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the ember dunes of Ashfall; Farmer weighs the day's bridges manifests and starts the calculations. 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 <= 3176; the input is a connected tree.

Example 1:

Input: 78 8 63 42 53 3 21 43 47 26 55 5 45 43 57 2 50 4 29 14 34 43 56 16 20 27 68 53 61 7 9 15 22 7 33 30 62 2 6 12 16 3 40 21 35 52 69 9 31 21 67 32 38 59 71 17 27 9 37 3 14 3 15 35 36 30 39 44 72 1 8 20 42 8 52 22 25 36 64 21 74 57 65 4 5 25 46 41 78 19 43 1 77 1 3 52 73 13 49 41 44 49 59 4 26 34 70 2 4 20 24 22 32 2 7 39 76 20 58 18 48 10 75 5 13 9 17 41 54 5 10 33 51 4 28 27 30 18 19 48 60 3 12 14 18 6 11 9 41 19 23 1 2 3 66
Output: 15

Example 2:

Input: 2909 894 2763 679 1630 708 1980 152 287 593 2826 1514 1746 1308 2563 972 1907 689 1458 1266 2420 240 256 229 600 1854 2283 2482 2493 106 800 351 705 1112 1346 907 1282 287 1086 1465 1860 339 518 927 1461 1216 1227 1720 2732 1213 1220 994 1774 917 2758 2563 2759 624 1049 1329 1389 718 848 438 1181 399 1665 119 822 196 526 1059 2302 365 674 1434 2197 964 1791 971 1527 1695 2785 834 1764 107 131 146 816 222 260 404 1022 292 2795 983 1943 220 1495 1005 2323 101 1109 1259 1556 306 2810 1112 2898 2260 2377 1954 2499 1672 2075 840 1574 756 2478 402 478 9 40 1111 1202 147 259 482 2821 889 1288 1358 2095 1111 1688 787 1358 2253 2375 1426 2661 752 1659 877 1935 880 2388 1323 1930 588 2329 940 979 2156 2466 211 1246 922 2681 1048 2285 91 196 1002 1608 770 1928 358 406 271 1415 611 1709 623 809 11 166…
Output: 28

Example 3:

Input: 706 40 84 352 665 154 323 280 365 55 115 319 417 25 27 569 638 37 286 436 442 182 295 13 454 209 550 177 346 535 594 153 382 258 443 295 351 295 586 143 204 272 466 155 217 138 180 483 547 6 428 55 94 186 462 37 106 359 515 16 42 1 11 79 497 504 587 173 566 9 307 94 660 200 258 159 163 137 348 145 343 156 247 42 107 260 378 405 654 230 234 422 585 408 646 54 59 236 520 82 254 143 604 99 319 94 239 185 529 115 176 311 438 43 241 464 556 113 229 594 611 8 149 48 150 75 487 256 461 131 227 57 385 86 148 129 489 124 280 641 690 465 682 428 510 125 493 538 635 12 14 191 352 56 90 313 563 275 564 105 183 259 681 291 606 408 694 37 70 3 45 570 617 304 436 85 313 182 498 302 518 122 221 89 642 94 380 32 656 85 578 64 703 79 154 78 568 501 674 237 561 1 4 24 81 106 159 348 456 282 496 216 279 57 55…
Output: 25

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Farmer's bridges Reckoning - MEDIUM Coding Problem | CodeTikki