CT39734

Koda's Longest Trail Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the copper works of Verdigris, someone must balance the workshop's books. This year the task falls to Koda, armed only with the bridges 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 <= 2029; the input is a connected tree.

Example 1:

Input: 1203 188 665 41 251 90 961 364 606 333 873 133 786 222 299 95 158 388 519 310 362 19 100 637 670 367 1014 362 1010 101 484 91 330 62 75 229 582 144 422 143 359 912 979 2 54 105 144 523 919 198 207 113 133 708 1112 7 142 379 544 552 896 420 1082 757 1024 485 626 8 623 357 1104 8 35 108 121 250 556 80 565 716 947 951 1144 81 230 137 1124 65 934 509 1009 417 826 45 46 25 724 56 1011 636 637 142 891 226 1096 25 304 62 451 78 118 237 261 277 669 400 434 267 448 920 1166 45 529 329 394 251 1031 523 948 537 627 136 278 1 27 326 516 18 22 92 320 141 703 357 437 365 932 12 60 223 265 294 409 135 418 199 731 112 482 789 898 178 421 130 252 105 321 402 413 267 539 54 166 372 671 29 165 800 940 174 1071 199 672 285 305 140 604 189 377 376 567 510 1084 24 346 1075 1094 136 220 233 943 75 874 44 164 574…
Output: 27

Example 2:

Input: 98 44 47 63 92 8 62 3 31 14 98 51 69 16 46 6 84 51 56 47 61 27 48 38 50 9 55 37 42 16 35 12 36 36 44 4 22 23 45 13 25 43 53 14 16 3 12 28 40 18 33 4 19 33 89 23 37 6 54 28 30 3 5 1 38 5 20 58 70 23 24 56 68 17 32 2 6 58 65 3 4 69 81 61 80 16 18 38 59 28 29 4 11 4 76 8 97 1 3 14 87 37 71 4 7 13 64 1 13 36 79 14 17 6 96 32 41 39 75 11 85 5 34 55 66 87 95 54 82 23 57 1 2 11 52 7 8 35 39 18 21 30 49 7 28 4 14 8 9 34 78 61 83 72 88 11 15 11 74 30 63 7 10 69 91 62 67 22 58 64 93 55 94 17 51 48 77 11 86 35 43 24 27 5 60 84 90 6 26 7 23 46 73 18 72
Output: 13

Example 3:

Input: 414 153 336 262 303 49 196 13 73 127 153 32 367 185 200 147 148 270 359 18 32 178 180 286 387 44 114 84 105 35 74 305 308 143 257 18 99 22 36 41 76 114 244 27 34 249 339 34 325 97 187 162 278 360 372 152 227 120 214 145 245 371 385 37 67 41 93 1 26 163 327 115 185 18 31 1 9 12 294 198 392 1 5 56 216 95 166 140 371 88 94 24 61 8 231 56 226 85 333 3 27 4 6 102 151 243 304 7 19 54 75 206 375 140 229 107 242 43 66 128 250 336 376 222 309 240 290 16 54 25 113 30 38 168 237 98 213 92 378 2 18 222 225 11 64 162 330 42 273 61 169 266 277 245 287 58 108 26 104 57 80 186 408 101 285 206 270 81 160 160 177 128 279 158 194 25 353 26 55 125 191 226 276 30 92 2 188 88 391 30 267 105 205 11 165 73 315 6 12 264 349 70 89 12 13 336 363 6 100 134 215 102 295 4 150 109 204 14 351 104 211 20 382 150 361 63 13…
Output: 24

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.