CT51127

Sable's Longest Trail Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Sable runs the customs house at the terraced vines of Grapehollow. Today the books show a list of routes, and the numbers must be worked out before sundown. 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 <= 1472; the input is a connected tree.

Example 1:

Input: 283 122 162 132 229 66 110 178 220 74 126 111 158 2 4 127 149 56 78 13 41 107 119 21 36 3 20 2 24 3 248 11 222 166 237 10 169 3 12 17 102 45 75 76 200 80 91 98 186 79 100 206 225 2 90 171 189 10 105 3 35 39 87 144 164 16 79 67 157 214 259 3 5 156 265 39 129 119 120 68 139 129 193 10 114 205 256 45 209 19 62 108 135 7 60 111 275 143 165 1 187 55 112 185 226 116 133 8 234 15 18 235 251 233 242 33 270 97 240 240 255 89 277 21 29 13 93 14 172 79 239 19 74 23 48 193 196 216 219 82 130 92 180 61 245 23 202 26 124 5 32 44 269 1 9 111 153 81 161 170 267 249 261 210 264 190 278 89 179 41 53 132 151 33 174 13 22 126 282 170 263 166 218 104 173 166 207 48 224 41 168 138 148 28 50 60 121 50 70 178 211 24 26 46 52 43 181 38 80 94 145 1 150 71 208 4 30 255 260 71 210 67 86 179 194 30 190 53 96 3 203 11 …
Output: 18

Example 2:

Input: 656 153 319 222 303 173 363 35 48 131 451 94 221 304 328 518 613 52 219 95 469 131 379 381 433 215 450 87 396 79 414 35 68 13 35 204 436 53 182 304 642 53 75 429 532 252 561 160 594 190 367 78 136 242 505 23 541 104 479 122 172 310 464 269 467 55 178 244 454 9 339 264 496 97 286 85 193 15 406 9 174 158 539 112 297 428 597 21 24 124 407 278 411 330 370 123 318 366 428 461 540 47 149 12 32 45 262 10 147 187 458 291 388 9 17 70 190 361 625 4 26 231 622 370 430 77 117 3 4 232 605 221 228 19 358 181 647 468 599 347 585 19 184 54 88 5 41 21 22 88 166 250 473 98 134 254 393 69 239 98 122 145 156 261 281 50 313 375 472 128 241 398 612 191 656 24 225 61 94 393 570 163 322 236 426 31 631 31 331 91 107 12 25 513 560 39 154 27 47 59 124 249 538 145 289 187 442 84 525 7 62 161 224 9 265 271 621 12 63 2…
Output: 26

Example 3:

Input: 341 22 25 126 225 264 327 35 187 114 123 4 36 58 172 18 26 206 263 92 329 45 238 111 256 8 93 1 2 117 186 23 41 57 167 139 214 16 34 102 119 31 307 126 175 6 10 46 105 149 244 136 252 148 278 3 43 1 20 13 15 27 110 113 181 99 291 290 294 50 191 47 158 89 179 83 169 60 161 33 149 190 262 16 50 51 71 260 320 143 150 231 298 283 330 27 53 79 91 122 303 46 64 39 72 18 49 8 44 160 255 8 11 164 257 80 277 17 302 41 48 91 156 12 21 29 63 31 274 147 201 84 180 147 185 56 124 248 338 11 80 41 90 131 160 28 52 90 312 110 116 25 173 1 8 3 5 71 134 239 300 57 219 259 269 160 253 11 23 221 295 59 176 17 99 15 57 232 333 81 96 44 115 96 228 87 240 61 62 1 279 131 192 7 239 58 133 60 102 20 77 45 280 3 13 17 152 20 151 45 88 35 98 117 126 157 188 31 232 19 76 87 129 211 324 80 217 18 87 12 112 24 27 220 …
Output: 23

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Sable's Longest Trail Ledger - MEDIUM Coding Problem | CodeTikki