CT51511

Mira's Shimmering canals

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the quartz ridge of Glimmerfell; Mira weighs the day's canals 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 <= 2388; the input is a connected tree.

Example 1:

Input: 88 31 76 3 33 29 83 37 48 41 46 1 6 7 10 2 16 13 56 4 8 60 71 21 39 39 74 15 32 2 4 4 9 4 60 75 80 13 87 11 22 62 67 8 29 19 21 5 25 27 49 8 86 21 41 44 88 17 42 10 28 9 12 1 7 5 51 50 64 38 45 37 63 4 35 2 57 6 53 55 58 49 79 30 55 44 69 31 47 5 37 8 59 9 27 22 44 9 17 20 50 10 52 36 77 5 14 12 23 1 3 3 40 5 38 15 18 1 36 24 31 70 81 12 30 54 66 6 19 8 13 23 70 12 26 4 20 37 85 57 65 60 72 33 43 34 62 3 5 48 68 25 54 7 15 6 61 52 82 19 84 9 11 19 73 1 2 66 75 8 24 33 34 65 78
Output: 14

Example 2:

Input: 892 70 107 20 147 89 726 125 750 16 176 50 73 16 61 202 619 551 576 279 545 225 792 94 623 10 214 173 614 411 488 152 290 464 837 533 802 8 440 312 316 41 192 581 824 132 279 610 687 262 670 28 66 321 714 157 268 76 91 54 548 20 72 5 15 145 378 20 185 95 145 263 270 1 22 24 27 187 570 1 264 403 603 668 848 16 238 443 858 335 383 134 299 1 219 77 332 496 793 55 179 303 540 80 186 94 336 154 283 18 605 4 118 202 710 446 475 824 879 253 347 48 97 591 695 181 399 409 410 20 390 214 435 227 775 299 302 395 580 246 405 475 798 175 706 111 253 459 892 393 508 28 104 300 362 42 177 197 631 56 127 127 690 61 102 15 135 262 506 227 342 380 505 425 520 797 854 189 635 28 70 260 567 352 396 588 701 17 84 199 324 186 202 297 474 489 645 613 688 205 634 177 298 440 833 206 365 223 310 488 643 8 9 129 17…
Output: 27

Example 3:

Input: 1610 1189 1381 519 1514 1273 1277 29 68 368 702 514 802 467 1492 68 93 261 907 335 427 25 358 386 886 285 985 216 1071 463 1606 11 333 250 1549 329 1520 309 1356 542 1026 522 1231 58 79 708 1061 614 1382 84 758 331 1004 262 691 96 138 76 378 562 1403 211 490 381 411 165 840 187 641 425 1230 1120 1590 315 428 1206 1236 564 926 105 434 16 103 42 334 79 447 397 602 141 1010 24 71 14 124 571 1016 449 1538 205 297 555 1487 158 412 11 498 1009 1271 544 1268 249 1046 240 932 273 1395 505 1257 255 556 227 1270 151 190 1061 1376 1183 1541 445 560 135 195 288 1229 215 1017 515 974 125 520 689 1374 218 282 164 305 828 1050 565 858 95 258 342 380 858 929 9 14 583 1409 127 339 100 437 84 353 180 845 104 1291 6 9 1200 1438 80 342 875 1334 782 1422 951 1430 67 201 22 29 1058 1561 23 965 90 129 180 1294 1…
Output: 27

Constraints:

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

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