CT35607

Blythe's Obsidian tunnels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the eel marshes of Slitherwick, Blythe records each tunnels in a worn leather ledger. The guild wants answers, not guesses. 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 <= 1702; the input is a connected tree.

Example 1:

Input: 349 41 136 204 244 134 283 1 3 48 243 192 237 110 344 161 261 37 47 119 330 47 251 89 124 102 294 128 138 20 48 11 33 222 235 324 346 31 58 183 212 47 289 16 108 62 83 250 317 104 111 99 211 54 129 113 290 127 191 72 178 20 200 8 319 13 92 26 120 177 277 10 28 104 225 240 332 51 197 29 41 190 318 31 55 38 340 184 242 33 93 67 76 8 23 5 6 116 145 96 195 89 224 32 210 54 223 90 161 50 68 48 184 76 130 96 123 1 34 15 150 284 314 291 292 49 221 86 167 86 114 37 280 6 65 67 139 57 74 35 135 133 185 51 187 36 188 258 287 33 49 168 325 15 295 6 337 25 230 13 31 43 173 62 81 131 172 151 321 138 229 126 201 217 336 37 45 44 198 21 26 50 142 92 181 1 8 43 89 242 255 47 148 102 272 28 85 146 171 260 307 113 131 1 40 36 88 43 105 149 323 80 104 9 339 60 179 113 166 100 149 15 72 78 132 43 116 200 209 …
Output: 19

Example 2:

Input: 569 252 285 70 177 30 102 240 303 497 526 115 225 70 124 154 187 354 485 57 79 13 64 33 191 10 409 45 250 36 271 35 97 456 494 167 507 86 230 9 18 47 322 23 471 355 440 86 516 12 182 10 41 186 281 388 456 145 249 269 340 238 287 158 284 91 228 40 94 183 256 92 178 28 73 96 211 21 152 19 134 294 390 144 327 405 546 38 190 25 530 11 20 176 568 18 23 182 380 12 14 19 43 286 501 62 381 33 497 124 563 54 223 26 166 42 204 9 40 19 32 72 162 361 482 126 135 38 74 2 4 320 391 51 140 55 81 338 527 506 515 446 467 40 75 151 403 402 454 27 29 212 324 88 432 1 2 116 206 50 138 160 220 210 282 146 263 70 163 331 343 171 566 32 39 285 427 14 31 164 293 9 72 119 252 62 306 455 551 14 137 92 510 219 266 190 333 173 242 164 254 64 217 24 48 262 335 8 128 82 183 270 567 18 24 68 148 223 518 144 203 364 522 …
Output: 22

Example 3:

Input: 1418 394 600 23 142 249 312 674 1281 380 653 34 201 101 135 210 438 504 532 379 585 164 511 99 191 11 129 235 884 10 16 191 707 66 344 819 1378 59 858 236 1283 497 615 802 1285 1201 1212 798 1234 605 681 424 716 291 390 436 895 342 643 404 628 37 250 590 746 230 447 828 1215 346 617 110 157 566 1142 136 189 268 505 1121 1293 47 164 74 337 97 520 114 854 908 1220 527 945 68 146 64 282 1013 1152 936 1147 300 599 1118 1416 158 972 147 200 239 545 69 117 163 267 286 528 495 774 487 1404 1011 1051 78 396 797 1076 2 5 42 766 198 487 922 1139 872 901 210 437 1002 1135 703 848 340 644 752 969 45 51 1251 1359 107 534 306 764 492 692 160 309 374 999 154 1277 78 105 782 1120 21 237 648 1080 435 988 563 647 762 1013 130 199 132 231 32 261 6 23 369 1030 922 1218 254 470 25 1205 23 168 95 779 751 1058 4…
Output: 24

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Blythe's Obsidian tunnels - MEDIUM Coding Problem | CodeTikki