CT48154

Quartermaster's Ledger of tunnels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the crystal caves of Luminar. Quartermaster spreads the tunnels records across the table and picks up a sharp pencil. 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 <= 3119; the input is a connected tree.

Example 1:

Input: 736 50 99 163 621 550 586 638 682 315 443 24 274 1 47 73 728 201 435 51 96 72 211 28 71 53 297 317 381 60 320 70 132 337 567 121 287 1 3 394 563 298 462 228 527 61 119 116 139 133 216 498 673 198 450 127 669 59 280 57 393 37 354 324 433 20 57 192 733 20 61 278 582 110 221 64 78 6 79 34 248 120 664 31 371 395 670 185 394 8 31 264 437 173 700 38 56 85 98 420 463 246 605 1 273 57 117 155 571 173 278 34 144 45 100 705 720 371 638 19 97 41 127 208 271 168 338 280 523 242 577 317 406 361 624 17 64 219 259 507 521 205 559 132 400 435 622 123 143 18 481 594 599 117 233 29 38 115 151 41 94 94 549 228 308 223 303 178 294 191 475 31 113 71 167 338 478 265 683 407 542 108 539 61 208 83 164 134 410 202 510 236 497 372 719 6 247 93 722 414 452 46 460 34 619 298 418 75 625 265 470 8 36 10 214 330 715 582…
Output: 22

Example 2:

Input: 694 99 339 1 8 443 649 523 606 283 324 245 538 190 451 49 330 178 607 50 217 160 340 86 141 83 98 139 224 122 150 162 209 349 629 9 194 281 583 72 503 382 526 22 45 358 579 273 287 464 660 155 347 145 627 70 640 26 364 124 320 111 165 56 240 20 423 227 463 9 53 49 267 249 348 13 49 179 522 21 69 220 459 179 327 563 598 280 305 40 199 21 337 468 541 65 164 312 653 251 282 29 112 15 27 201 334 29 460 113 509 139 650 125 163 167 581 16 273 25 336 105 149 391 496 25 142 123 516 35 121 6 570 97 176 219 254 194 632 86 124 113 131 13 19 453 535 40 612 7 130 140 300 52 156 155 310 133 588 598 683 76 486 57 85 80 174 95 152 38 293 427 528 4 74 53 685 40 129 308 323 35 203 31 56 35 107 181 331 31 39 447 477 123 227 105 138 143 464 63 392 61 455 502 634 6 57 2 18 109 186 93 94 578 661 76 375 215 585 …
Output: 23

Example 3:

Input: 2975 851 2769 1491 2352 924 1487 402 2419 1207 2558 616 2952 671 857 1064 1834 970 2430 1946 2362 1852 2803 1707 1766 1141 2583 807 843 1015 1243 115 165 18 1956 23 92 558 2072 681 2639 978 1973 1883 2366 977 1211 634 1053 687 1134 258 1192 198 492 480 982 1069 1269 564 575 1026 2297 1228 2478 929 1924 1614 2580 901 1198 2217 2550 150 369 15 279 2419 2483 1072 1415 1199 1294 2186 2638 464 1690 1256 1429 122 417 70 1149 1371 1808 214 481 1049 1662 1381 1963 1774 1858 1178 2075 20 121 893 1295 1343 1918 1166 2263 1262 2815 589 1408 1376 2518 290 2947 855 882 397 1831 2267 2291 241 1762 200 628 564 1869 2366 2807 1256 1857 1064 2436 1208 1813 1236 1591 1108 1155 391 2789 544 1069 792 2876 1163 1181 956 1083 1251 2192 229 477 1078 2345 1354 1373 1600 1812 2032 2247 1627 1632 146 202 908 2494 9…
Output: 30

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Quartermaster's Ledger of tunnels - MEDIUM Coding Problem | CodeTikki