CT39165

The Windward bridges of Omkar

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Omkar the ledger master watches over the windmill fields of Gusthaven's stores of bridges. A careful computation stands between order and chaos. 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 <= 2445; the input is a connected tree.

Example 1:

Input: 450 402 447 16 267 4 63 389 391 51 71 189 265 74 84 87 177 333 336 80 171 138 273 112 174 142 226 134 341 319 339 119 224 139 203 86 301 116 167 6 28 44 254 54 448 4 11 2 17 48 148 37 217 76 116 2 247 145 160 22 48 4 105 11 35 64 414 46 410 27 65 162 184 47 318 223 308 37 55 22 108 40 49 100 326 30 47 48 86 6 144 162 295 319 365 48 350 1 6 12 260 12 286 96 287 174 327 204 348 196 197 242 304 47 119 58 256 48 206 270 398 23 329 94 443 97 140 99 120 18 352 2 4 145 152 80 164 208 351 165 290 44 73 111 252 20 58 93 238 63 180 11 42 15 274 113 320 249 427 67 78 6 40 52 85 73 139 191 271 220 277 13 112 146 153 1 232 156 222 95 122 40 353 196 409 25 142 10 46 32 366 57 387 70 166 27 72 185 198 18 53 97 188 210 269 59 111 8 22 49 103 6 10 122 397 45 227 50 343 164 280 40 403 59 155 113 128 11 444 …
Output: 21

Example 2:

Input: 587 21 140 21 32 174 374 170 231 10 22 167 250 74 358 248 428 48 287 128 269 27 213 300 395 3 10 13 80 26 433 39 336 198 503 84 321 130 454 37 60 223 371 66 136 28 171 319 430 124 209 1 33 299 300 230 248 89 150 56 113 374 450 202 423 164 273 111 226 239 500 360 521 412 578 13 99 109 422 437 468 155 296 72 127 218 420 118 289 26 27 40 71 49 232 163 416 168 345 304 405 500 509 73 131 7 215 85 260 24 186 12 342 192 332 493 587 83 174 174 194 86 322 100 265 186 517 357 439 122 210 220 270 382 463 41 141 140 339 448 572 62 459 259 370 2 312 242 351 74 583 456 569 239 465 411 531 66 191 8 98 119 128 355 393 236 437 32 389 176 267 163 375 44 73 128 192 6 54 425 453 298 392 8 45 24 394 26 472 80 376 29 43 205 299 49 462 5 311 507 539 88 114 50 68 1 23 21 533 295 298 77 115 64 536 52 516 307 518 2…
Output: 21

Example 3:

Input: 263 54 79 33 61 22 24 16 43 35 73 159 227 109 229 127 224 55 95 60 222 184 238 143 153 81 96 55 206 79 114 66 230 2 3 158 253 32 115 64 185 155 157 112 126 2 14 53 165 7 22 239 258 49 84 32 97 10 32 33 130 52 74 7 37 32 155 59 136 41 49 92 184 10 72 67 186 78 217 17 228 23 161 109 209 200 204 63 85 65 76 81 138 163 236 59 239 5 12 58 214 39 240 7 129 84 197 3 7 201 252 38 142 30 36 107 149 3 33 145 216 9 102 7 8 95 113 78 125 83 166 73 131 68 109 4 11 27 105 12 16 71 123 84 205 32 147 42 107 74 245 53 65 47 64 2 6 61 77 198 203 45 101 58 232 99 199 109 256 80 150 119 218 115 122 177 200 149 257 38 110 36 39 88 156 14 220 142 178 45 70 141 192 196 198 1 9 38 121 138 144 25 223 29 58 22 48 66 68 2 20 52 137 90 106 37 261 5 27 69 202 170 213 9 88 189 234 2 13 165 207 26 35 202 212 11 31 53 86…
Output: 18

Constraints:

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

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