CT40778

The Coral tunnels of Aria

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the eel marshes of Slitherwick, Aria records each tunnels in a worn leather ledger. The guild wants answers, not guesses. 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 <= 2876; the input is a connected tree.

Example 1:

Input: 1616 398 722 163 487 489 1109 25 192 51 63 6 636 952 1273 1248 1583 812 893 698 1410 665 1448 110 144 1266 1351 359 1342 222 315 4 5 281 321 1157 1414 262 270 825 1177 57 1071 34 366 767 1379 929 934 409 744 187 513 593 1311 329 1003 319 1041 607 1086 399 1171 46 1126 312 667 573 1007 50 397 15 38 297 799 21 164 14 800 783 838 283 524 25 1189 176 954 38 374 282 1581 239 440 14 18 16 172 67 858 40 1596 433 926 336 756 265 584 88 344 109 174 250 763 245 1468 320 726 944 1580 1283 1334 301 586 213 882 6 8 699 1409 906 947 264 514 324 453 911 1098 801 1550 660 694 628 717 656 1349 41 320 11 940 125 1238 488 1609 1046 1507 108 444 1027 1421 908 1200 87 1411 407 716 183 340 937 1355 20 134 35 530 310 1336 744 971 1 87 1095 1466 291 1157 289 1380 217 1095 709 1571 192 303 167 230 638 1182 419 880…
Output: 31

Example 2:

Input: 2050 138 189 8 1227 1306 1340 558 804 535 837 37 796 173 787 655 864 160 1288 213 592 700 999 1218 1347 118 604 49 790 48 49 469 2007 641 1177 1204 1703 218 921 1496 1898 260 851 378 1282 1226 2031 336 503 1289 1917 526 1914 3 282 668 1713 574 1232 149 1381 476 1242 515 755 1808 1895 509 1834 1371 1473 301 950 113 206 234 475 337 700 235 1662 794 1213 998 1588 118 119 432 1849 711 1919 12 827 664 818 135 175 1391 1428 580 1226 620 1649 1026 1831 604 1617 238 900 136 892 8 1670 340 1164 572 657 635 979 1098 1913 842 1788 924 1941 430 555 848 1372 660 1759 95 103 1309 1490 398 485 254 427 293 1804 963 1659 44 1162 22 118 153 1470 843 901 160 590 649 1054 145 213 272 444 64 168 1552 1807 1284 1877 26 302 146 416 134 805 1126 1866 692 1967 329 423 201 767 404 1062 18 28 493 928 1454 1613 318 9…
Output: 27

Example 3:

Input: 1425 423 1053 1186 1245 437 1301 425 1130 79 166 250 667 11 83 40 88 426 639 650 890 360 1202 818 1170 310 696 213 351 462 659 174 1365 60 141 78 512 42 240 140 1201 410 746 38 185 86 778 385 771 469 1107 37 236 350 376 435 1013 120 843 43 464 105 208 1246 1383 321 931 303 836 123 199 700 960 26 1132 203 1207 64 1034 192 430 855 860 230 311 338 741 18 22 422 1375 450 568 1088 1283 309 765 315 391 185 468 118 180 311 519 618 968 396 459 286 536 759 1040 663 1115 27 112 1097 1260 1253 1414 135 378 131 229 225 697 718 784 97 440 13 327 252 721 162 261 190 337 681 1045 460 1399 238 296 584 1377 35 114 713 757 797 815 310 1037 183 651 254 256 779 996 65 1220 232 393 806 1229 164 168 1006 1387 450 943 822 1332 714 1038 40 313 155 1161 312 542 563 703 556 564 37 110 41 69 78 892 544 661 480 504 8…
Output: 26

Constraints:

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

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