CT54745

The Longest Trail at Duskwood

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the frontier camp of Duskwood; Xara weighs the day's tunnels 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 <= 1913; the input is a connected tree.

Example 1:

Input: 604 84 183 2 266 110 148 396 491 195 306 197 522 131 280 192 212 12 29 69 226 28 43 12 53 215 321 17 140 122 311 83 111 147 186 25 481 341 595 372 399 86 133 41 277 9 602 11 64 16 30 357 378 23 319 24 60 28 124 2 5 386 412 7 86 147 172 193 518 212 337 106 364 108 160 32 63 31 50 131 144 20 66 178 516 19 114 183 370 53 303 474 544 14 40 180 408 94 166 195 234 15 121 10 453 3 9 6 37 302 383 213 500 4 13 17 51 398 439 18 27 189 416 29 507 127 143 6 32 54 55 13 217 110 190 262 293 60 94 359 442 397 444 261 515 17 23 71 177 88 256 436 573 50 418 102 315 90 138 41 184 273 597 123 579 10 108 1 10 21 89 203 584 81 208 249 509 194 520 401 479 167 267 102 237 251 270 6 101 223 230 120 339 159 309 227 449 28 211 128 197 267 458 127 278 295 377 98 255 286 331 30 297 386 480 3 8 76 558 157 391 170 541 …
Output: 23

Example 2:

Input: 575 217 218 338 353 117 451 358 395 6 124 119 536 83 544 82 84 228 301 148 519 121 197 1 2 406 419 23 407 32 34 145 179 151 408 131 141 6 145 44 411 8 103 315 558 6 10 331 471 18 37 190 191 54 59 13 109 123 166 61 369 19 147 62 247 85 410 105 236 55 88 90 155 363 433 70 108 33 128 24 81 305 521 128 523 221 262 117 284 288 430 69 498 25 274 134 283 39 138 55 443 86 495 203 424 71 163 434 482 120 130 2 39 129 229 108 297 199 504 11 66 225 474 15 44 411 465 34 48 66 70 77 171 122 344 81 135 56 117 238 535 463 555 200 332 353 529 240 278 28 173 32 225 63 245 58 159 219 491 393 563 193 293 6 252 451 488 345 494 234 539 5 230 3 12 48 337 107 295 3 5 218 356 196 285 2 13 9 71 348 440 103 442 112 396 56 258 131 328 16 279 28 139 4 7 329 426 174 370 17 41 429 444 45 152 388 457 29 267 213 505 242 4…
Output: 23

Example 3:

Input: 41 31 37 1 11 4 23 17 19 9 14 2 3 3 40 27 32 1 2 14 39 2 15 3 7 3 9 31 33 20 29 12 26 18 38 25 36 5 35 5 31 1 5 10 16 25 27 5 22 14 34 2 6 24 28 3 30 16 18 8 13 9 10 2 4 15 25 10 24 16 20 7 17 9 12 4 8 13 41 4 21
Output: 10

Constraints:

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

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