CT48639

The Longest Trail at Echo Dunes

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the singing sands of Echo Dunes, someone must audit the season's records. This year the task falls to Forester, 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 <= 1578; the input is a connected tree.

Example 1:

Input: 1160 997 1095 80 1129 264 1160 521 819 105 129 285 645 11 915 32 1120 239 439 320 760 55 489 598 733 577 621 142 516 662 892 913 986 243 624 248 453 2 4 73 212 102 1133 556 1021 484 820 28 46 217 816 61 1139 96 213 109 332 43 59 455 753 354 884 425 463 121 142 40 255 994 1018 448 696 141 503 561 711 65 132 392 695 957 1099 223 735 46 709 558 612 64 148 371 502 592 1152 43 802 276 322 419 716 193 528 770 880 712 806 507 898 6 119 12 73 338 441 239 649 365 377 578 776 27 44 174 187 216 546 320 400 42 389 27 76 141 1005 208 1159 149 1056 32 209 467 588 387 533 154 491 38 774 234 487 142 196 728 793 356 994 924 1141 239 288 151 486 715 768 119 180 188 810 5 297 6 364 38 620 16 236 678 855 4 93 7 275 234 395 191 552 338 373 400 653 567 839 545 938 240 291 427 857 10 648 291 1037 331 436 28 135 …
Output: 25

Example 2:

Input: 1384 97 240 632 1114 842 953 719 913 95 1011 278 1138 172 1076 1223 1377 694 1243 1 1194 174 1238 82 406 551 786 307 399 30 330 504 559 159 1042 65 1161 34 1019 516 1384 341 505 199 357 358 558 431 724 601 1153 296 301 53 219 228 498 6 369 502 1133 215 1192 1335 1378 76 194 149 1280 588 862 253 627 565 750 584 684 549 1069 25 192 494 819 163 185 44 269 307 311 132 1162 858 1181 185 263 666 770 269 386 105 177 374 599 69 744 434 706 155 349 451 835 686 1096 810 1249 31 249 12 46 167 605 27 91 56 976 385 487 305 1292 561 960 332 471 954 1079 1191 1248 1122 1348 21 230 49 146 215 730 13 1220 411 515 481 1233 736 1008 344 1059 216 564 752 834 163 1288 1212 1240 503 634 615 799 36 336 511 939 151 713 389 809 116 922 1118 1358 1084 1287 22 467 146 629 919 947 255 994 102 1125 252 364 291 437 81 …
Output: 26

Example 3:

Input: 1118 20 884 515 770 397 524 112 230 14 44 101 138 40 592 434 676 5 6 906 920 169 368 295 443 416 591 58 228 349 1033 94 406 275 285 114 485 210 808 8 204 103 262 320 336 178 783 186 346 99 160 461 569 169 210 170 384 77 224 59 246 260 286 231 475 2 201 177 765 199 219 230 522 541 1039 93 229 292 441 248 277 858 1100 157 349 80 164 30 538 313 625 366 570 622 914 51 851 228 340 281 803 40 84 3 66 138 143 270 411 96 220 8 102 197 325 616 805 35 97 525 532 357 511 274 353 22 57 131 288 141 721 69 568 149 712 183 199 176 232 98 255 600 637 58 99 482 556 362 1041 517 762 625 645 447 782 649 664 136 901 88 372 4 172 320 792 68 555 53 659 59 226 268 323 190 410 315 1074 781 1083 234 602 120 672 932 1111 563 857 178 554 96 239 263 1025 220 243 106 407 109 390 182 188 668 807 172 385 247 509 90 150 …
Output: 21

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Longest Trail at Echo Dunes - MEDIUM Coding Problem | CodeTikki