CT53883

Kael's Silent Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the canyon post of Redrock; Kael weighs the day's roads manifests and starts the calculations. 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 <= 3006; the input is a connected tree.

Example 1:

Input: 1582 444 465 37 198 40 111 605 1559 105 847 1001 1242 11 89 1058 1285 34 320 231 264 215 605 709 1212 837 1230 228 670 842 895 102 480 178 184 666 910 80 119 117 510 682 1552 647 1434 780 1337 261 886 443 929 335 610 311 1126 61 388 60 295 74 223 738 1194 178 911 232 1100 167 980 1243 1553 242 766 1158 1186 627 1361 533 764 270 290 874 1502 510 1201 323 1020 467 519 280 506 47 1169 362 811 59 1073 594 1360 138 903 285 552 387 900 666 1462 313 1581 46 193 160 245 664 1503 303 704 261 1204 64 667 518 521 219 651 32 1504 548 920 7 25 1145 1309 5 248 347 376 723 1199 209 590 7 595 176 317 281 1383 2 433 264 1472 209 257 309 406 610 1141 621 1289 16 933 53 1528 279 379 32 366 282 949 394 1522 166 382 966 1381 686 1112 13 1247 439 472 232 1168 299 1550 404 1061 55 60 973 1500 419 1316 134 493 37…
Output: 26

Example 2:

Input: 52 10 47 23 30 17 22 2 4 39 46 5 8 12 26 5 17 41 42 6 48 35 40 36 52 3 12 26 35 11 15 24 34 2 29 4 27 6 7 17 45 14 39 16 19 30 37 39 49 3 10 16 36 13 24 12 20 1 3 3 23 29 51 15 21 6 11 4 13 15 44 20 32 5 25 39 43 3 9 9 18 5 6 3 5 16 38 9 14 12 16 18 50 1 2 22 31 23 41 1 33 19 28
Output: 11

Example 3:

Input: 2518 581 1166 35 772 306 1672 235 316 160 949 136 248 271 279 985 992 1612 1674 1300 1524 41 456 576 1839 408 2011 1159 1598 77 176 1151 2298 511 1466 517 2211 161 269 642 1984 254 356 107 647 287 805 59 2270 40 66 166 1260 395 412 1029 2147 278 397 2275 2435 711 1349 1121 1844 484 829 1694 2050 731 1342 290 801 143 1982 185 1908 1811 2158 326 659 1660 2506 413 485 158 973 77 1284 287 2070 703 907 642 1514 364 818 333 885 838 1449 305 1358 156 1160 2057 2113 1084 1846 1088 1828 1 84 423 2145 1315 1824 841 1628 1106 1804 79 1202 128 275 1110 1454 1784 2471 1458 2237 584 1258 738 1098 10 20 499 589 570 752 1771 1805 676 1272 1665 1926 301 2251 6 14 86 792 314 911 954 1034 307 443 117 952 2 18 631 1980 1561 2210 160 1879 946 1619 147 357 487 1663 42 163 572 1004 1715 2073 1204 1872 87 339 79 …
Output: 30

Constraints:

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

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