CT56825

Uma's canals Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the fox den of Rustwood close for winter, Uma must finish the canals ledger - one figure at a time. 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 <= 2736; the input is a connected tree.

Example 1:

Input: 2264 127 1313 689 987 635 1918 1479 1857 17 570 2 294 166 531 984 1985 213 821 757 1746 1438 1676 1564 1786 1237 1594 1764 1777 153 2145 803 1087 748 823 231 396 838 1663 135 279 1614 1778 439 1233 323 497 137 214 194 275 4 645 371 707 726 928 452 1315 511 964 17 136 152 344 458 872 459 943 955 1428 138 151 585 838 586 952 1271 2004 336 2040 1121 2201 1507 1799 925 1460 265 850 21 262 66 920 17 241 203 1527 1643 1798 55 269 149 370 494 2202 161 433 386 418 653 1992 253 603 1241 1442 600 902 1216 1521 180 394 121 508 906 1712 52 1910 67 257 788 1738 1407 1461 352 912 180 382 805 1756 145 643 899 1795 137 494 28 522 1152 2245 204 1263 1127 1745 433 750 363 2158 69 1066 1045 1478 96 1669 22 101 873 1873 348 752 690 1826 526 1443 378 1314 87 224 380 1282 499 1350 136 236 1152 1403 225 609 1272…
Output: 31

Example 2:

Input: 768 57 163 157 655 52 349 91 141 72 151 356 540 246 344 448 586 81 462 24 354 68 705 13 474 110 455 692 740 292 581 83 396 306 590 50 136 185 225 481 593 20 60 39 678 82 279 4 273 95 191 85 94 582 680 73 92 8 10 33 280 266 385 448 713 143 463 72 126 194 324 331 538 571 741 244 266 172 213 124 730 256 574 109 377 12 35 293 300 3 15 481 483 144 756 144 531 160 360 451 597 68 202 407 571 1 33 10 45 223 470 316 443 11 727 3 19 51 165 190 339 172 442 356 664 371 411 321 613 111 587 140 525 354 685 475 618 288 728 560 638 271 275 32 34 359 529 7 89 142 158 349 715 392 413 8 658 161 261 61 364 7 22 394 503 525 545 64 65 67 173 128 229 475 738 215 289 401 617 42 569 46 328 244 356 2 51 326 361 15 70 107 195 163 480 122 441 215 409 131 150 191 212 601 768 315 390 444 575 80 168 38 39 51 99 141 408 …
Output: 22

Example 3:

Input: 2631 687 841 149 207 545 2101 131 1898 1696 2015 16 1618 1394 1894 373 1851 6 844 1368 2396 227 505 79 307 1196 1524 1586 2426 416 434 1099 2405 247 366 1226 2570 980 1909 228 339 1324 1402 209 1119 1632 2159 258 1763 89 111 906 1214 94 263 817 1555 1282 1665 117 533 776 1412 606 2352 442 1737 147 666 262 739 33 2626 958 1468 4 405 1886 2257 507 1137 1670 1753 1306 1565 446 967 342 520 1871 2077 227 308 2075 2565 1584 2170 638 1855 1148 1316 75 417 758 952 3 136 51 332 121 429 311 1006 594 889 519 1052 379 1988 685 887 1175 2367 276 733 789 1576 1064 2255 139 2122 125 561 75 401 6 128 688 755 248 1585 24 1104 771 1578 344 882 130 694 131 358 952 2375 52 424 264 872 523 1247 327 956 537 665 1515 2143 331 1041 300 1582 2127 2523 464 632 122 1944 1535 1589 346 1485 347 2089 494 1983 291 343 7…
Output: 35

Constraints:

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

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