CT38602

The Topaz bridges of Keeper

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The store warden Keeper has been asked to inspect the delivered goods. On the desk lies a long table of bridges readings. 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 <= 1044; the input is a connected tree.

Example 1:

Input: 1034 615 1026 11 346 489 560 334 691 73 319 787 870 547 569 409 462 77 101 12 71 2 1029 619 707 114 607 153 248 258 563 314 377 2 11 548 643 505 572 548 932 117 800 19 80 154 383 130 151 850 921 474 674 92 483 296 564 518 574 23 501 426 458 157 317 64 79 614 647 89 1010 471 740 119 282 28 700 199 412 19 170 138 640 98 295 272 854 14 42 108 434 365 400 865 956 255 309 422 628 65 157 4 21 404 428 286 455 24 54 226 240 13 35 353 528 394 666 205 290 43 217 295 374 197 957 30 108 93 871 247 596 564 590 370 737 42 67 726 754 282 426 105 129 58 532 354 843 82 285 31 160 122 328 383 485 326 492 75 554 214 667 370 713 334 396 503 579 119 644 244 631 198 928 74 132 73 476 7 370 551 917 171 277 125 311 921 969 277 407 114 251 394 498 170 460 422 904 174 206 40 266 46 73 11 17 171 191 90 168 695 841 1…
Output: 26

Example 2:

Input: 657 46 339 112 186 206 372 56 351 380 491 116 178 102 486 10 158 156 167 144 456 66 116 466 619 153 170 35 215 274 579 41 49 434 610 208 282 8 545 4 18 202 385 26 137 159 253 9 96 382 588 414 562 21 229 294 353 47 123 18 209 518 641 311 468 285 478 37 212 340 508 31 35 193 395 185 203 117 270 300 305 111 202 131 266 49 412 153 197 164 387 184 244 17 30 153 248 143 373 533 634 114 390 354 386 554 657 333 389 172 526 248 259 224 274 159 207 23 308 322 530 43 222 493 578 486 580 390 642 4 268 215 312 436 629 19 100 253 360 239 398 94 182 137 280 31 32 14 42 115 361 109 357 4 22 466 607 46 56 370 404 122 223 240 414 109 330 577 656 12 29 226 290 51 615 307 458 484 559 36 64 526 553 206 294 73 532 72 571 315 523 117 163 13 587 218 381 155 518 357 376 33 450 20 105 227 292 298 626 20 149 2 234 1…
Output: 23

Example 3:

Input: 352 67 87 2 5 20 97 264 328 260 294 101 201 164 200 15 114 272 287 125 203 84 183 283 312 119 123 61 348 50 175 5 58 178 227 4 45 36 309 95 295 28 206 1 38 8 17 20 176 27 240 1 2 2 110 139 159 16 132 244 321 119 136 317 319 8 30 97 124 250 251 218 344 232 292 106 301 67 113 6 76 36 181 200 258 131 148 45 95 86 279 68 313 68 144 76 218 78 83 90 190 122 180 57 212 3 80 9 102 161 232 60 84 193 342 227 266 94 270 36 82 168 323 9 191 55 134 101 122 130 164 209 265 280 318 8 128 227 325 86 352 8 69 7 19 13 42 242 340 9 53 15 118 5 129 88 109 17 127 335 339 44 349 87 199 29 34 11 179 43 278 48 119 19 49 51 73 32 51 175 195 159 165 154 264 24 40 11 18 91 324 57 307 68 248 58 163 12 21 15 86 147 149 45 115 209 275 22 121 18 117 282 326 47 216 158 250 195 242 33 66 153 209 31 57 55 85 30 47 23 172 2…
Output: 26

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Topaz bridges of Keeper - MEDIUM Coding Problem | CodeTikki