CT53578

Quinn's canals Longest Trail

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the crystal caves of Luminar, Quinn records each canals 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 <= 1964; the input is a connected tree.

Example 1:

Input: 1445 595 862 495 1250 1082 1368 567 732 817 1016 486 593 444 1274 247 345 390 565 221 1101 133 236 143 251 130 1234 815 1035 508 689 222 228 585 703 711 959 168 633 994 1021 13 29 440 545 56 374 58 78 694 738 850 1047 1176 1264 227 230 1009 1157 53 410 27 162 42 211 305 718 647 1000 191 867 33 290 20 658 111 164 981 1146 85 271 987 1404 21 293 565 682 352 904 329 950 33 117 438 1095 94 691 818 913 675 1049 817 894 3 133 870 984 51 141 4 159 60 215 167 1382 344 1069 723 1354 6 18 41 1417 757 1270 225 1337 624 1280 11 163 689 994 600 1062 140 905 349 1310 25 428 411 747 92 1193 476 1245 9 357 949 1025 840 1009 1093 1392 201 1036 627 634 364 656 136 572 33 209 384 430 566 1271 1063 1182 430 578 564 587 187 1050 574 1294 148 151 151 865 270 490 792 969 635 1433 803 1105 2 4 429 940 1060 1159 5…
Output: 26

Example 2:

Input: 1396 394 698 1048 1322 494 638 989 1162 4 369 102 538 463 969 372 721 598 856 37 298 194 896 665 714 1131 1161 146 1157 52 72 365 388 462 907 920 941 179 453 59 1125 1232 1393 534 1093 163 201 172 1170 157 1207 807 877 625 672 586 999 16 1118 198 263 146 1295 42 45 162 707 213 606 468 1075 479 992 518 543 355 542 983 1302 113 243 593 832 35 294 87 108 204 488 770 1048 64 164 369 1108 1005 1006 339 523 257 817 603 627 191 634 556 968 47 100 62 86 584 595 102 349 32 55 493 917 475 939 356 515 696 980 24 206 226 742 393 1374 28 364 4 7 16 649 57 565 373 458 179 519 444 747 33 945 646 961 617 1151 374 1250 61 374 460 916 28 80 155 507 536 783 719 1365 21 268 265 448 23 291 657 997 410 532 775 1204 217 360 61 75 67 407 729 835 662 729 198 751 289 1025 874 952 1370 1394 709 928 413 505 389 599 8…
Output: 29

Example 3:

Input: 1935 1404 1451 1256 1509 114 358 31 92 543 1067 113 124 115 297 181 488 236 1456 118 446 539 742 205 1881 13 58 170 263 636 1742 464 1294 25 1521 978 1641 286 1491 1019 1914 57 1581 224 1114 434 651 62 1786 2 56 233 768 672 795 470 1353 153 655 364 1844 7 31 2 32 737 1003 321 548 498 749 782 934 321 1169 54 1736 2 17 374 641 84 109 22 81 688 827 1312 1866 633 809 59 734 793 1365 552 1241 468 593 446 501 827 1533 163 465 313 543 104 250 164 383 1416 1420 8 18 86 1263 736 835 1873 1932 178 325 257 1604 648 754 370 925 235 1147 143 1138 438 472 197 352 43 1179 1104 1906 1007 1063 743 1194 927 1388 22 166 584 736 304 1151 1592 1612 23 294 27 1149 948 1072 236 1355 499 1333 836 1205 280 692 447 1761 256 524 1540 1709 217 756 310 323 87 421 1363 1597 255 781 90 240 892 1880 449 1765 934 1101 189…
Output: 27

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Quinn's canals Longest Trail - MEDIUM Coding Problem | CodeTikki