CT42490

The Longest Trail of Galeholm

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the zephyr cliffs of Galeholm; Ivo weighs the day's corridors manifests and starts the calculations. 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 <= 1202; the input is a connected tree.

Example 1:

Input: 688 111 318 174 548 121 164 200 231 217 422 56 67 28 269 155 409 312 526 6 113 290 319 485 663 43 520 81 385 233 281 298 446 53 130 26 399 2 59 8 36 278 568 108 355 9 11 35 53 46 180 266 412 171 268 41 237 40 61 255 271 72 135 225 273 202 624 86 120 2 9 277 392 11 155 266 482 213 436 17 521 32 369 193 219 219 481 33 147 306 529 22 337 331 450 248 345 30 444 342 560 203 247 39 234 268 387 474 583 19 45 63 302 76 165 71 200 145 252 224 394 38 267 104 532 121 263 9 72 23 251 193 594 44 65 62 467 55 71 77 143 622 628 38 39 306 687 188 472 23 84 73 206 52 512 496 600 255 478 331 410 185 255 15 262 58 80 228 452 564 618 309 348 273 282 60 498 130 295 52 77 291 648 63 119 34 617 192 265 70 95 480 544 237 463 313 533 17 179 86 122 137 292 223 312 189 291 117 643 270 362 92 631 137 468 345 426 71 1…
Output: 25

Example 2:

Input: 850 91 223 40 56 376 819 174 695 25 28 188 525 179 826 9 13 192 328 580 672 89 219 64 287 67 166 41 57 588 740 72 159 26 53 436 605 618 719 16 685 8 104 121 280 125 492 294 436 155 814 603 718 50 160 203 308 61 248 130 235 15 447 127 376 122 212 100 629 31 75 147 368 530 778 368 460 7 201 492 747 69 807 72 239 375 485 132 835 142 300 631 712 128 184 39 326 10 59 39 154 141 360 148 430 84 100 9 12 167 421 15 457 23 573 341 493 285 639 10 17 555 731 579 658 5 42 375 786 70 186 349 800 23 73 279 440 274 742 180 253 234 372 60 133 268 361 366 489 268 335 219 517 516 698 66 93 126 668 47 257 77 692 254 406 214 757 319 716 222 302 55 76 1 8 142 774 819 836 360 403 19 113 298 363 65 172 598 729 200 616 479 598 18 20 536 761 225 529 14 334 546 571 133 170 5 123 170 423 464 522 3 26 363 456 35 250 …
Output: 24

Example 3:

Input: 1177 763 856 225 411 49 79 619 1086 84 554 2 4 16 300 10 66 151 927 156 964 109 174 28 1079 384 892 118 870 666 1025 13 1078 505 1113 348 807 6 244 14 48 540 955 190 805 435 1037 165 466 157 395 368 385 155 204 823 861 1061 1167 221 472 139 846 671 1110 1 45 110 1041 3 38 264 988 786 862 889 933 910 915 462 680 12 380 134 474 1027 1160 219 248 361 735 243 1032 727 815 557 578 397 667 156 394 185 687 84 171 505 728 146 427 593 990 58 121 41 642 394 767 667 871 92 1102 613 661 8 570 2 43 213 249 28 152 119 536 20 766 139 228 91 276 34 670 342 1023 25 821 104 131 435 623 288 549 388 590 849 1028 258 1093 483 1164 33 63 400 458 74 179 8 398 71 463 624 776 184 995 40 556 13 494 800 809 103 888 332 495 1093 1095 255 714 331 629 13 286 108 344 66 889 124 708 90 285 31 51 269 476 297 826 747 787 5…
Output: 22

Constraints:

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

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