CT39899

Dora and the Marble tunnels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Dora the auditor watches over the eel marshes of Slitherwick's stores of tunnels. 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 <= 3085; the input is a connected tree.

Example 1:

Input: 2870 323 1352 469 1505 770 1462 26 282 471 849 757 2776 103 243 878 1179 407 932 817 1207 116 1293 265 714 356 388 629 881 991 2417 121 147 602 1643 245 725 797 904 675 2262 1561 1939 772 2239 15 34 881 1138 357 1679 152 270 403 1007 801 1467 5 475 391 2669 1386 1469 93 504 1221 2112 288 1390 948 2304 445 1194 277 644 23 1314 1703 2502 508 2211 152 170 1467 2015 44 360 884 1928 1808 2445 1224 2597 671 1189 49 107 29 480 694 1995 1077 1612 2267 2848 206 2006 656 2052 432 2682 687 2056 1933 2506 407 1957 278 789 108 313 209 303 831 2069 2131 2237 576 2153 404 683 39 404 1082 1750 275 2342 232 1485 64 2620 711 1482 391 1899 439 720 1677 1999 1449 1823 100 727 3 67 1936 2321 164 215 239 434 1153 2288 1857 2120 2192 2756 234 2450 858 1406 6 64 2171 2400 1 4 18 1273 47 445 1261 1921 407 2024 392…
Output: 31

Example 2:

Input: 1296 77 137 319 575 316 332 62 123 834 986 115 821 32 40 195 619 600 912 148 655 83 501 803 1124 1 877 195 664 353 377 342 447 525 557 167 816 127 635 216 281 80 1077 240 300 627 844 203 546 531 1179 56 353 199 381 31 1162 140 555 363 405 222 409 574 625 87 932 77 192 108 1098 282 512 571 836 4 30 125 400 646 1022 457 629 269 403 686 1172 1253 1281 363 887 735 866 483 753 1079 1213 1201 1286 48 217 161 313 757 990 40 113 811 1033 395 681 351 394 94 587 109 1252 113 535 542 713 49 50 236 742 132 344 167 564 505 1006 720 1241 461 620 121 440 494 1232 86 383 68 783 119 1111 302 370 451 924 193 1259 788 827 33 103 83 182 345 1068 297 1102 13 237 29 41 445 962 28 98 594 672 344 1249 170 665 802 870 56 80 49 189 275 982 592 966 40 739 763 858 214 987 582 1247 590 1145 162 176 23 238 472 614 54 6…
Output: 27

Example 3:

Input: 1354 451 1170 815 920 1064 1279 155 189 38 674 65 99 65 682 191 1308 461 463 658 1005 1 77 3 600 122 769 259 1187 774 1311 273 1096 287 417 752 1224 819 1317 847 1247 606 1158 77 173 25 61 224 927 71 745 174 419 12 552 49 167 225 1304 469 1033 469 1294 545 876 51 557 176 525 137 928 246 683 45 174 723 1070 177 1173 267 649 78 109 181 540 516 1163 12 79 162 362 605 725 26 44 150 233 667 1013 66 252 257 275 2 365 68 102 192 352 40 105 555 889 3 7 552 971 22 957 466 906 902 1184 209 603 490 656 75 296 111 655 10 172 429 685 631 704 76 82 926 1210 15 20 357 914 1063 1174 216 534 376 451 287 1136 21 498 58 93 694 815 487 760 612 730 404 1047 267 939 526 755 657 1007 580 1030 347 1213 181 204 45 1071 553 1335 101 908 695 1099 43 94 86 829 475 1205 340 790 30 148 570 1256 218 941 565 578 102 200 …
Output: 29

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Dora and the Marble tunnels - MEDIUM Coding Problem | CodeTikki