CT47256

Vigo's Granite bridges

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the crystal caves of Luminar; Vigo weighs the day's bridges 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 <= 3871; the input is a connected tree.

Example 1:

Input: 1953 21 262 465 914 90 843 1096 1601 1026 1154 390 729 660 1055 89 442 231 1465 354 653 704 828 35 753 148 265 488 1344 87 308 115 155 57 515 211 430 327 656 20 224 37 1359 989 1320 188 1794 411 950 82 321 798 801 436 1610 216 747 1164 1225 229 368 1011 1861 1715 1881 437 1842 199 705 180 217 605 904 529 648 7 112 90 894 1612 1787 133 905 399 1676 59 205 2 5 82 268 55 654 230 881 97 1102 343 558 634 1115 227 584 264 474 430 1134 1019 1824 1337 1377 247 605 801 1281 477 1454 302 454 765 1555 33 233 405 1164 1281 1409 247 1152 293 657 627 738 976 1068 191 324 113 490 17 545 37 240 1035 1223 267 812 1222 1573 164 525 1152 1514 1344 1846 271 1018 714 858 359 409 1359 1524 7 1934 159 577 653 797 1 2 602 1093 102 1195 404 1147 80 95 54 214 25 49 1463 1548 15 1381 332 590 1 4 8 206 276 1715 842 1…
Output: 29

Example 2:

Input: 2806 2298 2545 845 1224 1245 1870 449 1181 416 836 279 340 246 1137 926 1268 287 864 29 2146 232 971 171 1013 1377 2794 163 2083 176 383 678 1178 469 756 391 811 295 446 1249 2113 289 346 1804 2552 297 834 320 1503 221 484 118 1347 327 1055 33 1921 145 963 1879 2672 122 701 398 403 686 2402 1283 2423 884 1424 9 172 452 2279 1103 1291 1543 1897 1002 2150 637 898 327 1759 39 66 302 335 2392 2401 11 572 113 2389 605 1154 372 1702 161 1076 245 438 842 1485 1082 1714 1022 2320 1160 1482 810 1900 4 2315 1398 2171 175 1470 1473 1625 316 370 83 118 222 2161 590 1406 76 1008 1338 2016 593 1126 38 57 482 748 469 1019 13 186 194 930 1785 2280 1869 2709 291 1273 79 158 373 534 63 287 1458 2282 187 1957 347 2506 1531 1849 2252 2681 1570 1968 372 545 1935 2762 78 547 198 884 1831 2480 962 2502 917 2561 …
Output: 31

Example 3:

Input: 1974 790 1619 163 1943 165 176 239 320 318 487 322 340 461 1616 1336 1586 1526 1859 1801 1973 466 1322 279 940 470 760 199 345 1184 1510 781 1791 878 1014 986 1608 2 910 1324 1529 23 941 659 870 13 79 712 772 393 600 589 1347 722 926 838 1160 52 76 152 192 85 242 540 1210 715 1434 270 1564 499 507 1701 1860 296 1217 423 1106 1315 1344 971 1802 100 310 13 1846 372 905 205 228 329 743 785 1626 1253 1507 541 1688 525 545 1136 1885 785 1115 75 339 582 624 597 789 400 493 1085 1227 282 797 410 549 55 634 541 1796 365 1157 240 440 13 819 24 475 1186 1362 918 1761 124 606 70 213 507 1162 411 1572 181 262 203 779 477 604 771 1912 473 1666 848 1092 413 1880 25 33 241 1474 2 12 1048 1658 554 1107 923 1592 1510 1560 1064 1757 1068 1389 1334 1379 962 1414 316 608 716 793 1884 1911 17 25 61 197 935 139…
Output: 33

Constraints:

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

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