CT47860

Sable bridges Longest Trail

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the beacon hill of Lantern Tor, someone must decode the foreman's shorthand notes. This year the task falls to Rohan, armed only with the bridges register. 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 <= 2025; the input is a connected tree.

Example 1:

Input: 996 139 203 112 294 6 10 85 171 15 186 145 965 384 540 355 381 288 392 150 393 158 429 127 286 10 110 100 501 106 877 624 648 301 354 276 305 336 395 164 486 556 752 348 924 803 892 1 62 151 860 29 475 377 920 469 899 186 804 718 822 545 616 511 958 389 715 72 248 6 271 56 158 249 384 226 681 57 189 151 225 208 772 382 404 247 618 542 838 343 448 652 990 260 564 397 780 514 792 77 682 325 386 660 881 81 91 185 579 3 34 37 984 382 879 44 961 388 623 280 538 507 774 549 728 135 233 746 975 148 849 136 572 430 758 86 200 102 985 127 480 212 578 32 162 182 968 83 127 191 352 403 406 169 711 2 26 63 108 49 763 172 278 121 206 3 7 32 195 403 621 564 868 271 938 398 604 40 320 171 989 310 855 609 722 468 589 768 953 143 270 44 175 276 602 383 420 669 732 19 133 352 422 396 627 16 71 608 898 8 13 …
Output: 24

Example 2:

Input: 1270 71 291 68 235 144 232 90 858 440 510 100 112 211 646 200 662 1054 1268 474 1167 389 514 75 384 285 286 646 780 30 124 47 395 457 471 6 81 151 957 148 885 208 947 463 902 514 863 97 114 239 593 28 34 275 288 263 727 86 1065 49 414 196 1041 61 378 523 990 745 1029 36 117 577 1159 416 604 668 1058 68 96 127 159 82 89 411 1131 87 1113 1036 1060 1000 1238 49 93 56 398 165 466 144 1045 362 668 524 939 312 996 141 262 31 836 269 408 229 949 54 88 354 631 209 1227 398 801 1207 1209 505 649 630 992 570 623 753 798 924 1196 23 113 250 645 17 259 34 179 664 1092 539 759 396 886 541 852 315 1039 739 982 615 985 31 53 305 485 276 607 131 482 136 619 229 320 17 18 310 887 1124 1218 438 698 279 1031 341 406 65 237 8 312 200 370 228 603 90 892 74 431 491 685 55 353 204 300 507 659 5 22 175 644 382 81…
Output: 27

Example 3:

Input: 1059 144 360 270 526 386 551 346 673 115 658 149 854 212 687 292 428 504 521 34 168 337 910 6 702 223 225 174 319 408 645 343 364 56 414 285 841 234 422 852 959 909 1000 457 563 299 317 760 908 274 381 790 982 49 133 16 587 618 749 16 90 170 261 39 476 608 937 698 787 358 736 193 458 91 134 441 750 503 1042 102 321 309 378 15 129 62 79 201 376 274 552 530 600 268 623 33 35 10 43 170 213 545 944 98 153 274 296 60 595 165 523 5 918 400 616 596 670 937 961 486 806 7 23 145 280 709 769 340 495 80 316 29 47 518 634 338 842 288 432 318 347 465 833 394 567 807 917 46 74 233 242 59 713 175 836 467 1051 419 862 359 920 215 962 9 10 14 40 252 337 150 164 503 728 433 843 245 811 461 577 141 753 43 579 704 897 230 305 306 400 185 771 257 516 20 38 79 410 134 136 241 585 225 444 336 457 28 105 12 248 1…
Output: 29

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.