CT52350

Warden's Ivory Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Warden inherited the customs house at the lily shoals of Padmore along with its curious bookkeeping system for roads. Time to make sense of it. 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 <= 2450; the input is a connected tree.

Example 1:

Input: 1563 494 1273 205 554 383 1142 86 1138 15 110 734 1280 175 1384 925 1380 604 751 572 903 883 1096 252 1200 40 124 663 766 394 720 89 477 705 1168 668 784 17 131 853 959 509 551 7 142 140 259 1305 1422 58 151 172 516 1397 1484 737 1148 162 214 185 602 154 229 591 1228 158 210 83 95 120 122 260 555 47 59 80 120 57 68 925 1098 14 894 1040 1093 1 9 404 1139 145 604 311 1307 658 769 315 613 928 1048 23 1316 680 823 550 935 28 37 25 63 197 338 288 576 263 1113 63 711 562 709 559 853 248 805 27 453 276 449 325 404 37 43 219 374 264 1336 299 1234 30 1322 9 234 782 1355 118 708 47 105 386 1224 607 619 278 1255 237 347 39 66 354 756 869 1359 31 137 249 939 97 1560 610 713 104 174 83 280 910 1557 185 1032 1024 1177 115 1343 61 560 126 165 162 173 191 471 779 1001 346 624 1042 1301 197 654 877 1479 10…
Output: 27

Example 2:

Input: 736 78 83 65 524 20 522 575 597 269 386 378 605 390 711 66 76 215 244 77 385 350 700 110 152 221 312 142 265 206 478 339 394 294 610 22 294 23 34 517 526 240 424 8 117 50 169 204 397 31 50 237 430 161 443 214 243 399 404 537 661 31 39 124 484 540 690 223 331 44 71 402 658 361 405 154 557 7 599 355 444 226 266 96 150 170 351 96 472 35 56 424 471 22 560 258 635 352 714 126 450 164 500 206 279 8 32 90 344 243 421 363 580 415 459 127 172 224 514 597 692 43 614 241 316 106 525 190 195 5 79 339 399 25 273 137 513 61 395 30 107 412 530 104 302 1 69 77 426 198 547 84 206 141 460 312 579 27 37 145 190 241 416 350 510 186 191 113 137 137 494 366 387 207 255 286 359 12 422 471 563 104 296 32 398 112 178 60 160 416 619 408 537 142 228 14 72 157 194 21 22 81 94 146 183 174 673 406 668 95 406 37 68 17 3…
Output: 24

Example 3:

Input: 334 71 192 3 9 3 126 60 134 163 322 169 313 117 267 6 66 17 27 7 30 10 229 50 82 113 327 32 71 162 264 58 234 114 279 26 156 115 291 42 81 75 77 23 167 57 121 176 251 31 97 14 39 29 237 122 169 186 319 133 216 2 292 77 87 7 86 204 315 31 43 70 90 212 218 61 141 77 172 2 15 204 271 154 285 5 21 48 270 82 193 112 116 4 6 210 212 123 300 27 297 187 323 155 230 14 73 3 7 279 298 247 294 36 47 90 96 47 189 57 165 72 108 227 236 6 12 116 197 165 209 206 257 44 61 43 240 95 190 8 303 194 235 19 23 141 255 6 177 97 306 266 307 6 88 220 277 301 304 22 44 26 79 67 215 214 222 103 201 4 5 71 178 223 278 14 33 172 246 53 153 50 83 110 180 11 18 130 176 92 124 26 29 72 200 251 310 166 272 70 104 24 28 1 2 25 69 8 250 56 115 14 63 127 266 2 84 95 166 153 173 10 11 1 4 10 208 128 233 143 286 24 50 242 25…
Output: 21

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Warden's Ivory Ledger - MEDIUM Coding Problem | CodeTikki