CT53487

Last tunnels of Harper

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Harper inherited the depot at the ivory gates of Alabast along with its curious bookkeeping system for tunnels. Time to make sense of it. 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 <= 1874; the input is a connected tree.

Example 1:

Input: 1044 413 517 151 736 399 695 825 915 201 539 300 572 382 857 16 63 114 156 20 23 158 639 113 143 366 930 112 477 579 1023 322 946 135 439 158 171 342 389 120 146 24 74 12 26 220 454 308 825 39 169 320 714 227 427 254 394 26 30 66 228 787 873 71 711 29 710 553 826 105 470 36 234 179 788 28 541 96 922 25 261 1 6 119 932 393 691 6 7 36 279 175 869 15 53 509 516 410 642 228 325 348 601 110 764 67 117 103 206 45 533 107 891 150 336 146 494 79 904 59 77 572 905 208 465 199 798 134 327 827 890 732 824 310 611 22 194 242 1022 110 349 34 838 85 160 814 849 183 214 746 802 232 380 61 162 5 587 243 659 25 762 151 387 98 165 440 464 233 510 266 347 35 75 634 906 773 952 325 982 110 615 446 700 70 252 142 173 152 195 55 177 98 127 746 804 395 960 347 562 23 500 744 888 693 1015 79 805 148 285 574 955 1…
Output: 25

Example 2:

Input: 1751 462 836 62 616 110 261 403 1638 636 1021 511 1652 144 329 434 1446 999 1539 990 1161 147 880 77 1030 141 207 1322 1362 448 728 262 1068 673 1209 136 589 48 502 511 866 427 1424 94 454 325 482 433 592 247 476 710 1713 698 1412 868 1100 638 981 811 1575 450 585 119 1489 487 1527 24 322 555 660 493 516 377 643 677 1712 533 652 472 979 498 932 1280 1361 364 645 1069 1202 649 705 371 1391 435 856 66 203 275 598 279 656 219 265 98 608 572 874 69 221 1683 1702 77 912 859 1674 2 4 113 136 431 697 446 1589 634 1029 597 881 1111 1474 1222 1294 120 415 87 1392 440 664 244 1183 12 39 432 1154 830 1334 486 1287 119 210 622 1282 48 157 189 862 11 135 1507 1701 142 245 1044 1443 4 10 182 239 472 566 859 1138 141 232 351 368 549 1227 314 864 107 345 661 1370 348 813 39 553 247 271 755 841 565 708 260…
Output: 26

Example 3:

Input: 1076 70 238 24 255 46 297 94 101 39 43 153 335 308 465 258 415 53 112 974 1027 4 23 305 593 825 1071 252 740 65 996 11 58 172 395 242 652 393 611 200 217 357 623 13 104 309 543 532 539 518 911 35 202 141 449 211 254 259 727 106 282 12 396 45 955 208 508 251 330 10 19 277 342 59 96 269 556 22 146 4 892 922 974 149 676 135 283 108 324 39 72 111 291 339 989 330 874 16 688 98 175 13 15 8 750 1023 1054 1045 1049 162 232 178 775 362 682 503 900 695 1064 414 523 688 1047 60 337 453 962 824 1037 54 193 209 296 334 790 363 667 197 559 181 837 714 802 101 304 385 506 92 653 244 569 2 8 443 552 215 305 345 404 939 994 86 615 607 982 537 947 76 80 595 949 39 40 928 942 241 478 560 1036 1 451 482 545 878 1065 28 168 202 757 292 603 349 393 19 166 201 494 333 935 369 965 805 838 371 1026 296 400 314 521…
Output: 30

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Last tunnels of Harper - MEDIUM Coding Problem | CodeTikki