CT46472

Omkar's canals Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The surveyor Omkar has been asked to outscore the rival chapter. On the desk lies a long table of canals readings. 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 <= 2508; the input is a connected tree.

Example 1:

Input: 2450 695 1797 1357 1560 4 509 1293 1805 315 1034 229 233 83 189 1531 2309 1227 1917 820 1499 1080 1627 28 78 612 699 446 582 248 283 905 1258 1065 1787 213 1722 563 1431 8 21 154 1864 2199 2318 556 663 276 2438 149 462 603 1752 761 886 772 1364 286 604 103 214 298 2269 668 914 657 1483 627 700 518 1351 1840 1916 171 543 1706 2095 1771 1793 953 1873 972 2392 450 768 821 828 23 972 1332 1650 317 542 5 19 1157 1330 287 1062 160 777 470 705 545 2145 1614 2325 398 619 1090 1091 33 45 1174 1520 1028 2064 159 163 535 630 657 726 334 552 217 825 309 1558 718 2198 1974 2014 591 1833 245 541 937 2172 1016 1259 434 2426 1825 2081 468 863 1376 1632 1530 2216 374 1515 248 1895 1167 1490 372 1197 1029 2268 219 1349 1367 2051 1779 1909 407 997 27 99 2228 2338 859 1118 72 388 1095 1247 203 1508 1731 2039 …
Output: 27

Example 2:

Input: 1129 141 360 514 688 177 719 94 223 6 143 87 186 16 536 49 289 261 760 26 33 114 217 16 123 19 914 394 451 353 506 329 556 36 213 66 184 325 334 444 866 163 356 281 910 317 646 126 135 66 791 1068 1083 724 967 475 522 83 664 180 486 73 850 127 705 156 1054 269 410 104 275 60 235 215 243 376 521 279 745 83 311 420 1082 121 160 518 520 85 386 55 74 891 902 377 550 2 134 778 1004 19 85 498 1013 126 261 2 7 446 788 1 16 69 405 198 1100 21 941 259 277 235 335 65 106 5 8 789 926 622 627 237 806 204 583 245 328 340 899 169 942 81 267 661 1051 63 330 67 70 39 180 293 463 259 787 94 236 248 680 484 796 32 119 31 183 31 64 88 127 568 1055 149 254 785 844 27 48 532 825 18 904 693 843 15 257 102 589 177 592 622 905 43 155 23 59 124 246 665 852 3 29 43 537 478 700 30 378 830 1076 584 736 83 375 889 928…
Output: 25

Example 3:

Input: 937 70 196 186 365 146 307 632 641 219 755 11 25 282 295 8 193 36 46 259 284 73 290 136 547 112 748 57 794 81 359 373 669 168 473 28 599 26 27 96 248 84 136 16 551 280 667 115 184 177 472 4 764 65 147 128 296 678 729 129 152 331 505 105 261 171 342 165 797 24 896 209 225 3 29 57 676 111 932 171 374 25 127 568 864 338 487 1 47 464 595 75 575 116 156 286 673 519 801 20 87 1 8 231 722 535 612 142 214 142 735 188 228 225 527 500 541 180 334 416 532 14 15 728 843 227 747 67 534 188 628 68 198 90 272 322 925 243 511 357 728 678 842 188 361 60 67 642 736 17 116 123 574 277 396 726 910 183 555 232 706 12 123 85 623 199 422 296 846 548 758 73 443 261 546 17 179 58 346 468 588 375 654 204 536 373 605 304 723 130 354 201 553 570 865 177 923 68 244 14 597 280 320 106 174 51 601 799 880 291 308 93 657 …
Output: 25

Constraints:

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

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