CT49244

The Longest Trail of Frostgate

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Morning light hits the northern keep of Frostgate as Fletcher unrolls the day's manifest of tunnels. The tally will decide the next shipment. 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 <= 2553; the input is a connected tree.

Example 1:

Input: 189 35 40 140 178 52 143 50 153 116 172 58 98 11 41 95 162 124 179 30 66 26 114 6 15 36 47 33 44 17 31 45 68 64 138 37 71 6 130 73 110 11 23 26 29 140 188 149 182 35 160 10 60 23 159 41 84 11 19 57 183 11 109 83 104 70 125 148 174 107 133 15 121 15 117 48 50 2 39 15 82 44 92 87 94 59 106 64 89 50 101 5 10 5 154 9 27 9 11 90 129 64 128 33 56 7 8 88 135 52 164 7 171 77 142 38 140 78 157 86 100 16 20 22 148 1 111 25 88 27 58 52 96 170 177 67 78 32 33 112 145 83 113 77 79 19 62 95 139 4 9 1 48 35 36 118 126 14 46 48 67 86 185 99 155 83 134 70 76 8 38 31 103 33 137 100 152 21 32 2 45 10 136 45 65 6 34 7 83 57 165 63 156 11 51 1 4 23 170 1 2 17 22 50 55 3 6 20 105 133 163 140 146 117 176 3 5 87 102 4 75 26 108 32 99 33 43 35 63 7 14 11 107 18 21 5 12 4 24 1 3 40 72 48 161 10 42 150 151 108 124 1…
Output: 21

Example 2:

Input: 650 8 49 114 167 79 353 210 509 295 525 91 255 142 417 385 554 72 190 363 386 267 458 101 217 47 131 215 286 10 25 47 51 323 351 232 399 391 450 473 573 386 403 294 496 42 250 340 517 8 62 384 622 35 475 172 393 99 153 217 345 197 208 17 28 500 557 137 145 181 443 286 628 87 648 106 328 171 218 106 196 63 124 378 508 43 125 13 532 216 363 274 413 87 402 126 164 334 336 351 559 472 582 29 82 18 623 539 574 2 11 426 633 284 619 134 192 26 404 316 348 45 77 74 111 217 334 259 511 230 268 34 133 8 9 101 114 304 389 388 440 146 220 291 498 217 224 67 630 45 173 331 453 125 538 37 604 123 599 3 90 236 339 143 433 284 467 67 86 14 40 90 474 27 266 228 308 320 409 195 213 34 146 32 53 440 471 237 315 18 38 74 481 174 300 96 468 153 229 50 235 169 512 263 267 220 461 3 33 14 422 191 226 37 132 484 …
Output: 21

Example 3:

Input: 1002 185 502 620 986 377 409 314 430 226 398 210 496 214 376 98 107 223 431 15 39 539 626 184 549 372 397 220 417 193 314 151 250 755 855 211 453 176 192 46 201 3 5 78 475 74 809 45 86 562 835 679 795 31 463 276 483 302 779 100 1001 265 745 523 614 543 622 508 931 25 495 36 412 28 913 262 544 123 266 490 557 51 508 360 785 250 326 72 129 31 585 723 749 325 758 894 898 430 478 185 304 144 393 364 878 91 563 205 320 48 287 264 426 178 793 134 991 132 159 148 176 9 103 8 702 62 596 334 876 791 873 369 693 66 302 311 884 225 378 480 822 146 752 838 863 412 764 55 694 131 760 443 715 17 110 635 865 359 704 589 742 353 396 1 9 167 974 765 912 453 470 29 74 687 827 272 688 11 75 377 564 692 897 3 114 178 186 111 328 94 947 543 567 84 124 256 395 21 73 77 244 235 239 88 387 93 120 774 960 106 139 …
Output: 25

Constraints:

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

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