CT37970

The Longest Trail of the Hidden corridors

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Xavi found an old ledger of corridors in the dairy attic at the lantern district of Glowfen. The margin notes pose a precise question. 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 <= 1103; the input is a connected tree.

Example 1:

Input: 371 187 344 56 165 138 307 245 367 70 259 13 18 32 50 140 146 176 210 51 143 251 322 122 245 1 60 28 96 130 150 170 339 23 251 28 358 17 33 6 8 34 83 139 263 73 91 65 147 111 326 23 364 25 52 20 176 72 139 63 181 136 278 12 39 18 144 326 357 225 305 29 130 6 160 278 362 150 248 70 84 160 209 64 355 145 269 69 225 3 49 38 40 108 145 283 319 4 338 113 241 91 93 111 112 51 212 210 288 193 371 236 351 5 75 103 327 28 193 54 162 233 347 297 299 147 306 183 198 245 324 2 5 26 265 1 41 43 54 47 56 236 337 69 113 23 221 66 206 108 149 68 71 110 184 72 170 68 228 209 313 125 300 196 213 147 222 85 196 53 177 38 82 197 336 82 101 50 81 259 349 127 284 72 106 271 316 50 103 19 127 91 97 36 85 12 44 110 161 124 208 53 134 24 27 133 262 79 115 101 346 132 275 59 258 192 199 66 207 58 72 184 256 7 20 46…
Output: 21

Example 2:

Input: 958 339 656 27 179 705 757 35 278 163 403 29 807 55 70 119 272 244 880 145 260 231 284 157 702 86 94 86 304 430 483 525 607 52 153 551 596 307 922 4 377 288 543 444 797 194 232 172 186 311 376 356 660 191 788 262 277 564 706 279 317 3 391 68 116 323 476 62 193 51 653 51 487 277 454 115 675 84 512 538 648 298 353 26 48 196 211 119 302 609 686 21 560 360 375 441 802 82 157 169 496 103 216 59 112 83 709 100 196 203 239 67 532 485 486 68 758 257 853 301 898 19 28 545 714 500 815 845 902 116 591 172 388 496 501 233 247 27 362 20 582 244 868 119 445 121 181 236 437 110 228 163 818 15 201 166 231 408 778 169 380 207 379 80 100 451 463 182 314 71 330 448 912 382 600 155 374 108 398 363 637 15 166 338 339 25 587 82 567 65 85 133 288 85 488 51 428 454 951 324 400 425 628 835 839 419 507 77 99 75 168…
Output: 29

Example 3:

Input: 603 97 143 199 208 96 302 49 58 186 374 24 44 9 267 143 182 40 210 4 35 167 295 65 247 39 114 264 564 292 310 453 555 381 576 97 209 338 349 38 89 104 261 260 356 255 329 149 332 61 200 3 4 512 546 72 241 6 10 169 218 98 426 268 316 306 341 302 526 169 269 125 240 319 333 214 450 31 33 98 158 210 392 12 167 406 493 107 223 151 196 434 538 261 305 85 224 29 215 14 15 71 132 161 549 5 6 17 46 207 413 479 581 8 108 78 312 5 26 149 331 180 410 206 516 57 379 135 588 164 443 24 80 43 270 35 262 162 488 186 236 38 489 297 301 164 205 89 597 83 120 159 227 163 412 25 40 9 383 326 501 36 94 87 230 341 464 106 159 30 179 53 251 41 104 63 234 143 421 146 478 26 442 73 77 87 125 26 367 46 461 13 18 251 513 178 281 63 112 46 180 185 237 329 449 221 363 55 97 457 587 274 320 465 524 8 22 42 101 287 355…
Output: 26

Constraints:

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

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