CT36937

Smoky tunnels Longest Trail

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the quartz ridge of Glimmerfell, someone must optimize the storeroom layout. This year the task falls to Elowen, armed only with the tunnels register. 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 <= 1102; the input is a connected tree.

Example 1:

Input: 754 347 420 154 195 2 78 61 91 15 59 23 50 353 735 449 461 498 568 266 528 44 426 460 661 101 155 182 534 318 381 143 715 45 271 10 22 363 445 530 681 18 52 248 463 7 24 567 722 110 374 222 478 346 665 19 23 348 586 305 482 563 749 43 92 118 138 232 576 417 627 235 593 356 704 7 85 45 87 39 718 3 11 107 145 18 565 98 697 16 258 264 322 658 696 189 632 323 326 238 305 616 642 199 621 80 133 509 671 63 64 71 114 80 288 450 514 17 452 124 206 150 187 178 657 243 716 111 262 106 209 389 555 348 369 120 588 44 230 409 737 20 470 392 518 1 8 116 144 8 502 478 602 428 489 224 394 62 69 46 81 40 120 421 561 192 269 232 545 4 9 162 342 105 331 287 373 95 705 360 431 41 62 182 249 136 397 244 752 10 99 134 719 162 215 343 564 476 583 132 194 36 451 148 241 126 160 19 140 126 312 37 203 498 676 230 3…
Output: 27

Example 2:

Input: 479 23 55 9 15 101 295 262 435 128 156 71 120 407 412 32 109 67 470 10 198 63 209 47 472 227 287 271 399 14 20 12 59 38 147 92 184 80 122 159 257 30 41 316 384 1 4 150 467 59 139 22 24 234 370 295 410 132 348 161 272 221 398 240 444 203 290 113 157 183 394 32 360 148 349 91 281 139 289 142 218 98 159 150 163 2 3 331 427 28 54 69 162 12 126 36 90 378 395 18 22 9 18 93 107 74 463 41 58 105 260 49 210 75 407 94 417 250 344 77 288 372 391 191 311 36 71 154 225 50 68 24 81 113 169 187 317 94 449 222 259 72 201 65 313 108 312 163 172 322 329 49 51 73 79 110 143 161 242 174 214 91 433 177 396 182 229 25 106 12 35 104 434 175 297 453 474 161 296 3 37 278 303 265 351 91 280 119 196 14 302 273 355 200 205 45 425 70 98 24 241 24 266 38 234 208 224 158 328 112 197 39 53 111 268 14 251 202 271 145 174 …
Output: 23

Example 3:

Input: 1066 422 537 92 497 370 1023 28 42 837 860 99 511 69 296 53 150 290 314 68 395 116 884 275 731 19 94 449 496 45 458 67 913 625 744 54 817 850 895 299 1059 813 848 90 143 160 532 21 299 227 292 325 409 709 917 55 306 211 477 35 417 11 45 126 437 495 664 412 837 106 171 684 736 571 605 184 478 277 768 204 238 136 696 63 242 117 234 339 1044 104 971 63 807 4 110 9 716 49 92 124 1004 256 338 220 685 162 189 139 621 17 20 54 773 161 763 571 830 67 475 787 820 123 1045 413 925 10 385 36 197 758 1035 30 492 153 951 92 493 56 205 82 206 405 908 469 1009 659 871 289 655 50 754 67 259 128 651 5 255 66 701 285 984 420 553 8 49 195 456 342 992 208 877 410 1063 433 516 638 739 210 293 677 780 289 460 213 289 257 471 593 811 65 507 70 847 48 157 159 470 68 139 522 737 396 809 10 72 419 978 23 77 79 920 …
Output: 25

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Smoky tunnels Longest Trail - MEDIUM Coding Problem | CodeTikki