CT35809

The bridges Longest Trail Puzzle

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the mulberry rows of Silkmead with crates of bridges, and Lila the auditor must account for every last one. 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 <= 3233; the input is a connected tree.

Example 1:

Input: 14 4 7 6 14 1 3 10 11 2 5 1 2 2 8 5 9 1 4 4 12 5 13 5 10 1 6
Output: 6

Example 2:

Input: 2603 352 562 132 198 742 2416 89 1502 278 1581 120 1345 261 1229 1087 1924 1622 2076 976 1606 147 761 506 1668 2103 2175 282 654 738 1806 1411 1582 44 117 489 1274 346 743 301 1389 36 60 318 2019 316 965 70 324 671 1319 463 1724 150 219 433 1732 93 1231 256 282 245 270 455 2177 658 929 1774 1901 1512 1595 1416 2447 66 993 188 1438 1439 2042 89 2148 692 2381 273 772 45 97 490 2387 129 168 55 288 533 672 792 2001 366 414 1 96 127 1838 637 828 200 1378 1964 2024 915 2043 409 2020 551 1210 1233 2201 605 1083 584 2129 253 335 1366 1780 519 587 431 2032 2025 2077 923 2527 175 310 1137 1742 1 8 1156 1750 1248 1479 44 1473 1003 1327 520 1455 723 1252 1956 2127 301 969 820 1396 1121 1309 125 410 817 1025 368 449 1858 1977 45 381 823 1560 68 2112 1060 1163 647 2204 332 1017 385 1046 675 1850 533 245…
Output: 27

Example 3:

Input: 1445 677 1057 78 230 641 646 3 21 184 699 1031 1059 669 1021 20 24 522 1168 732 876 137 1102 313 1381 936 1196 427 1230 1243 1363 437 1150 424 651 13 603 779 1384 71 214 826 835 542 1293 1028 1258 1200 1224 531 881 64 237 784 920 213 516 265 347 52 109 624 659 66 384 299 365 76 1120 108 284 799 1172 529 907 1282 1306 52 409 21 41 891 1108 879 1243 237 382 429 680 249 821 122 260 36 49 20 1025 1083 1121 262 778 13 28 743 880 668 758 185 383 395 1213 386 436 1010 1096 446 456 572 791 27 698 188 333 16 749 1 5 722 1283 476 507 409 608 92 717 8 89 1128 1176 621 1443 151 190 141 225 222 944 2 1324 433 783 30 238 938 1227 154 529 534 789 1090 1254 1123 1178 189 213 843 1266 43 458 612 932 620 731 170 677 637 661 788 1238 12 63 271 773 688 853 319 598 477 1177 440 984 205 419 43 366 303 760 833 8…
Output: 32

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.