CT56093

The Obsidian Shore Longest Trail

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the basalt cliffs of Obsidian Shore; Rowena 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 <= 1064; the input is a connected tree.

Example 1:

Input: 946 107 129 790 929 63 620 169 782 140 757 524 633 558 803 248 260 582 882 75 232 168 196 262 879 24 245 366 653 139 363 531 604 486 617 40 426 289 855 157 382 15 148 122 688 469 675 78 365 8 531 551 723 39 43 36 287 19 534 581 731 53 530 557 830 655 794 261 764 328 526 135 323 191 398 116 356 251 256 94 175 36 41 44 376 33 178 9 38 66 104 293 643 66 98 842 909 33 132 226 637 49 163 10 331 688 813 861 892 16 732 66 128 49 167 365 511 553 811 573 590 207 936 426 865 602 804 132 907 135 143 360 756 36 182 105 124 327 330 549 644 307 413 704 827 291 745 1 2 539 740 124 460 299 468 212 718 264 812 36 350 778 904 189 209 183 342 418 456 19 474 342 494 171 843 89 671 160 570 351 636 182 433 264 577 233 720 171 314 9 22 210 237 1 20 417 615 152 370 104 117 54 427 57 192 270 362 548 752 97 100 147…
Output: 27

Example 2:

Input: 296 10 51 9 83 81 174 69 95 59 176 213 220 12 23 29 62 29 94 4 18 78 163 65 257 122 204 130 238 44 61 85 107 19 285 129 185 194 228 161 177 172 255 48 115 58 131 14 40 49 178 6 148 28 36 189 245 27 82 81 88 34 155 4 39 131 151 57 289 267 269 14 21 181 292 2 5 93 113 42 127 125 126 154 162 27 273 59 110 131 222 10 247 5 121 125 267 6 64 257 265 41 112 18 69 46 295 50 279 5 17 31 60 138 164 90 242 22 37 129 145 24 181 6 29 4 13 2 28 27 32 5 7 69 106 4 189 23 25 48 55 194 219 199 281 53 71 87 213 219 263 166 284 124 191 90 264 77 146 36 184 23 74 170 225 26 190 1 2 184 200 78 166 115 192 61 90 1 8 111 129 164 171 234 286 4 6 154 224 170 266 98 99 1 31 122 215 248 259 49 50 97 116 7 235 23 87 152 261 59 79 39 227 77 78 67 142 82 123 134 143 30 134 55 91 18 252 95 187 38 124 21 101 41 114 22 63…
Output: 18

Example 3:

Input: 753 19 61 403 458 239 240 28 71 119 311 5 56 538 628 160 182 17 230 138 441 362 454 109 325 10 26 121 261 276 496 352 638 73 328 92 332 72 249 171 447 105 178 29 62 68 138 194 602 96 244 24 170 140 391 88 381 175 529 670 725 649 687 88 426 189 274 151 195 8 34 190 201 108 518 158 175 170 276 37 526 29 309 55 389 35 273 184 218 168 618 480 522 130 503 3 11 45 637 312 538 45 46 140 164 42 207 3 22 420 626 23 181 383 708 258 584 100 136 109 196 413 736 1 17 87 94 11 658 360 509 66 163 204 394 109 139 77 133 267 414 154 508 162 321 248 302 268 614 147 494 617 654 5 363 115 131 13 69 194 473 286 716 248 723 90 277 124 733 71 97 266 547 628 641 23 216 426 696 123 480 13 45 527 704 148 517 577 702 95 208 149 236 21 54 57 96 100 145 118 395 3 4 150 387 13 21 202 351 587 744 243 270 46 146 125 485 …
Output: 23

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Obsidian Shore Longest Trail - MEDIUM Coding Problem | CodeTikki