CT56917

Admiral and the Wayward bridges

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the peat bogs of Mossgrieve with crates of bridges, and Admiral the valuer must account for every last one. 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 <= 3688; the input is a connected tree.

Example 1:

Input: 769 349 371 13 34 65 162 107 415 46 57 273 532 343 439 25 453 99 766 87 367 341 408 25 73 399 624 91 151 108 170 20 175 233 358 84 270 475 488 158 327 190 233 64 569 310 501 290 727 28 376 627 763 245 674 19 174 168 191 69 394 56 258 27 275 29 215 263 352 313 734 17 306 476 499 9 28 23 190 17 27 686 751 394 467 618 700 133 146 102 240 303 487 20 33 3 114 74 479 5 651 81 378 317 465 10 149 308 350 48 519 311 684 222 252 54 410 172 338 433 464 53 97 6 195 81 194 71 294 610 627 97 313 14 339 325 541 127 260 11 88 82 158 50 93 747 750 4 92 171 695 7 94 27 47 713 738 567 593 3 186 295 423 342 546 296 391 615 618 115 363 124 229 137 671 243 262 11 19 225 737 203 226 62 99 108 225 59 289 87 219 44 206 399 634 5 11 21 67 322 368 83 128 34 40 100 366 197 209 28 105 494 653 246 641 64 89 502 706 447…
Output: 24

Example 2:

Input: 1032 48 875 671 852 325 369 95 766 44 261 140 250 280 606 60 761 346 628 709 871 2 30 302 707 371 589 571 612 170 320 107 274 392 490 753 775 168 443 195 365 459 815 179 279 107 330 90 232 47 627 619 965 777 826 190 417 203 367 488 521 192 685 224 1020 33 407 23 69 972 1024 759 857 205 269 310 578 197 882 570 805 148 710 393 429 47 138 8 105 309 881 482 979 515 705 43 108 312 953 35 175 59 86 766 797 350 673 102 224 46 223 104 266 107 986 22 454 126 188 52 144 397 788 72 194 10 242 126 211 107 655 69 651 48 523 105 884 208 924 473 866 58 78 186 280 708 925 251 561 441 858 209 216 34 96 543 887 31 129 204 555 350 630 336 518 399 850 98 165 413 466 28 740 1 251 817 939 56 60 254 1023 351 720 987 997 308 312 282 618 103 309 92 98 632 883 49 836 197 297 71 141 272 591 463 478 75 148 22 629 231…
Output: 25

Example 3:

Input: 1306 669 687 376 1268 174 690 623 758 583 1248 138 777 807 861 131 256 68 619 173 440 117 453 410 1122 979 1094 616 957 25 360 430 581 1 8 88 150 223 1235 335 739 164 252 352 514 6 140 72 373 88 1256 35 87 25 117 971 1074 137 217 37 351 523 1032 502 642 790 823 7 23 875 1014 445 526 477 962 30 100 66 591 573 1115 51 430 1044 1085 332 550 169 955 688 1141 68 270 60 557 652 757 119 182 299 1290 222 827 677 1120 332 380 585 772 816 942 125 1095 918 1079 863 943 58 123 593 1117 243 633 310 553 51 852 418 913 431 599 261 504 160 414 437 609 15 27 331 476 234 374 59 208 435 1250 863 1078 31 1298 382 818 5 26 24 436 609 1283 570 576 305 668 309 1019 106 959 258 568 293 343 656 828 43 1193 653 1259 599 608 409 953 156 163 227 228 645 665 90 232 805 1237 419 614 97 976 461 1066 5 883 594 613 646 65…
Output: 28

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Admiral and the Wayward bridges - MEDIUM Coding Problem | CodeTikki