CT45170

Innkeeper's Shimmering corridors

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Innkeeper runs the shed at the railway depot of Cinderline. Today the books show a list of corridors, and the numbers must be worked out before sundown. 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 <= 2420; the input is a connected tree.

Example 1:

Input: 1975 582 894 87 494 893 1377 281 492 228 1004 665 858 256 833 133 197 432 523 1001 1539 1498 1820 260 339 428 759 871 1640 42 298 1382 1888 50 153 1377 1497 1080 1700 257 1055 158 396 991 1519 1174 1586 1452 1715 788 1009 732 1120 401 682 788 1020 969 1493 640 1531 1746 1844 952 1482 550 719 484 757 90 326 1776 1893 1829 1940 507 878 1528 1970 114 128 50 81 371 571 482 1338 201 556 43 75 499 1032 154 1071 5 1046 3 239 505 1693 498 944 220 865 1092 1560 810 1725 176 256 653 1696 873 1513 315 1716 411 1442 293 537 9 100 201 1342 166 1667 864 1196 596 715 149 302 104 1134 1273 1745 949 1389 1438 1545 1654 1886 1030 1669 77 530 911 1179 586 705 853 1227 36 185 138 425 50 78 678 1172 1900 1958 38 39 7 27 255 703 589 872 172 601 292 1352 226 352 42 714 1296 1944 188 208 546 1213 980 1008 101 194…
Output: 28

Example 2:

Input: 1580 18 211 140 200 774 817 515 835 1151 1479 33 67 148 634 132 503 159 656 181 824 50 64 228 229 1067 1273 887 914 694 1445 181 494 23 1124 211 220 401 546 1142 1230 73 1314 68 1201 365 421 1244 1294 133 278 566 1123 740 1101 270 591 648 830 732 1375 418 475 337 1544 5 92 159 188 278 552 246 996 1182 1256 537 1214 835 1264 320 1209 1265 1560 635 979 407 1394 646 1389 661 1107 828 839 676 747 358 397 122 136 385 410 1 4 88 181 45 574 532 1125 345 564 403 1151 111 515 15 43 305 749 336 967 233 303 902 1085 1101 1390 88 285 907 1098 54 130 187 323 334 342 476 975 613 1133 90 309 482 1232 370 970 319 937 127 134 456 625 923 1138 119 231 720 1459 107 771 385 1139 314 368 422 435 1108 1341 242 762 578 848 463 676 528 558 92 681 407 1450 443 479 211 216 475 924 213 985 397 805 9 125 548 1271 5 1…
Output: 27

Example 3:

Input: 2154 1077 1967 257 1139 367 1802 495 1163 78 101 1098 1405 184 244 13 72 634 771 456 857 110 333 357 1248 633 2058 713 2020 196 322 1073 1564 67 818 183 747 715 892 547 1100 1382 1761 3 22 1703 2139 1209 1484 567 1019 487 1256 840 2119 225 427 102 1252 746 1059 1292 1956 443 613 203 988 107 681 161 189 300 665 245 1697 291 1672 166 236 85 147 1094 1533 215 347 1172 1585 1324 1829 231 326 166 612 619 1316 104 1259 73 334 1320 1393 124 1237 146 866 817 862 554 1561 1489 1951 295 384 5 33 998 1611 381 1188 419 1395 1363 2068 770 964 509 1242 165 1670 644 1609 1155 1314 290 1542 835 1499 949 1189 949 1782 899 1051 942 1412 298 1439 45 123 117 324 717 1813 254 1018 237 726 176 188 201 1034 1146 1234 404 2090 480 1249 657 1457 1390 1845 642 1304 289 1011 219 249 378 411 1857 1999 313 1663 286 15…
Output: 31

Constraints:

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

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