CT46380

The Longest Trail at Bluehollow

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Keeper runs the cellar at the indigo vats of Bluehollow. Today the books show a list of roads, and the numbers must be worked out before sundown. 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 <= 1250; the input is a connected tree.

Example 1:

Input: 694 17 165 498 661 17 302 277 667 350 539 92 118 205 233 177 426 479 501 215 255 61 252 203 502 37 60 33 140 33 39 38 544 319 658 16 45 11 505 202 455 387 390 6 586 153 243 241 323 117 619 93 628 132 263 269 329 112 675 254 309 286 417 38 510 479 596 112 171 274 289 19 30 194 635 430 478 45 56 1 11 191 273 151 234 95 173 95 535 22 108 240 251 32 434 320 690 348 680 188 458 197 484 122 196 60 351 32 91 525 537 211 242 154 207 34 66 2 10 24 687 312 511 23 27 45 411 144 444 79 318 195 300 76 126 53 335 132 310 106 230 142 475 200 659 126 134 89 128 537 630 34 657 274 423 18 116 445 636 82 437 370 593 48 143 75 111 259 364 28 247 97 215 32 135 19 33 179 379 46 183 10 138 145 401 607 622 43 121 81 139 91 94 17 37 1 35 52 83 84 294 333 470 5 74 183 216 50 328 166 448 18 157 390 400 7 299 105 653…
Output: 22

Example 2:

Input: 382 21 26 95 98 157 342 102 105 110 358 145 156 72 259 148 269 238 282 5 142 161 266 56 251 183 223 73 87 3 7 44 132 56 241 156 328 94 206 212 299 180 327 143 187 109 147 91 344 286 381 69 153 128 366 35 119 212 267 31 41 24 102 10 14 119 232 276 316 277 294 128 318 263 303 42 88 78 369 6 145 54 312 4 22 282 357 14 30 15 62 4 37 78 375 1 13 29 120 251 380 49 106 165 183 85 211 48 210 321 347 24 50 109 200 7 16 38 91 263 324 17 90 210 308 331 356 162 245 90 326 96 181 16 158 86 262 14 173 131 298 167 330 26 49 64 192 44 73 53 96 98 172 118 242 116 170 277 320 60 64 167 268 256 310 72 345 1 58 19 66 100 166 285 293 26 141 4 9 89 114 3 12 102 116 71 219 158 322 219 329 76 84 127 195 57 196 7 38 4 17 282 290 27 48 229 288 33 193 30 349 180 336 134 236 184 367 25 55 144 216 188 359 1 3 16 302 3…
Output: 19

Example 3:

Input: 622 311 395 268 383 17 74 376 582 112 502 5 60 77 271 80 239 162 359 564 588 198 384 13 41 293 336 17 470 382 483 144 550 315 440 146 452 132 156 30 320 411 424 130 453 18 506 109 122 201 246 128 569 375 618 119 332 56 177 460 505 431 512 285 581 397 402 294 608 220 229 35 43 465 531 40 46 29 97 2 47 18 125 55 248 131 171 159 160 100 317 3 399 69 235 325 521 162 439 456 497 203 298 112 288 166 352 157 194 395 467 102 291 22 119 34 170 127 385 242 498 64 83 98 353 275 490 8 568 479 609 26 381 308 444 77 430 109 228 179 242 334 405 124 558 158 528 287 379 92 604 262 378 65 187 84 139 146 199 103 518 424 436 6 30 376 536 2 176 76 481 96 183 1 98 41 145 230 571 2 21 374 579 131 133 425 508 338 387 53 391 140 282 9 14 424 455 16 79 136 404 152 537 238 294 511 586 91 376 7 135 408 592 9 398 279 …
Output: 22

Constraints:

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

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