CT48972

Secret roads Longest Trail

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the honeycomb cliffs of Beeswick pays by the answer, and Gino intends to earn it. First: the full register of roads. 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 <= 3782; the input is a connected tree.

Example 1:

Input: 1062 807 889 98 487 351 833 24 165 9 465 34 524 114 777 6 26 84 288 244 931 151 345 1005 1059 236 259 81 255 206 563 256 613 437 818 180 479 815 838 46 100 397 619 480 729 179 892 32 807 553 755 750 1051 663 1041 702 868 150 409 26 243 181 629 140 678 62 714 88 341 491 581 68 148 855 962 239 348 107 154 93 920 435 795 99 113 128 206 158 322 6 314 107 1013 501 647 88 163 11 112 663 853 628 978 836 859 101 342 236 249 100 189 343 941 90 116 262 601 205 395 110 635 704 846 91 454 139 636 59 219 759 1029 608 723 4 183 545 659 304 394 8 10 146 770 657 800 175 239 19 145 952 967 295 353 64 461 497 1028 92 147 239 1023 122 433 201 543 348 987 190 553 398 410 685 986 183 222 222 393 480 785 43 240 523 768 336 565 384 600 201 882 148 712 16 576 656 672 610 968 609 1039 367 644 686 855 160 316 134 9…
Output: 27

Example 2:

Input: 3029 2 4 1376 1620 6 128 169 246 478 997 1494 2840 226 979 915 2165 169 2749 1229 1861 348 1517 407 656 680 2735 857 1069 90 443 12 832 162 1546 185 946 127 497 336 353 826 2716 907 1096 240 1288 183 294 926 1748 105 359 245 2641 2113 2787 274 1175 1984 2904 4 33 2586 2964 133 181 47 818 742 2798 971 2119 8 17 345 1345 98 376 412 495 998 2611 863 2637 511 1866 2 3 703 1224 478 2870 1464 2359 1238 2129 780 1577 344 2163 369 702 1351 2084 1173 1808 58 82 1527 1859 117 144 1530 2080 1165 1178 1000 2894 160 621 1186 1568 470 2313 1255 1631 308 1591 2 76 332 1432 509 1884 1712 1801 1944 2194 622 2896 1957 2609 819 950 1224 1469 102 185 474 717 310 1422 1429 1657 352 2316 180 1837 811 1397 1576 2425 441 1180 129 191 454 1217 849 2897 328 845 449 553 221 1249 17 248 15 2741 160 397 1301 2766 1552…
Output: 29

Example 3:

Input: 1661 261 1503 192 781 34 92 77 1229 1593 1613 316 1040 231 647 80 584 734 1620 180 1495 144 1617 372 684 749 764 954 1625 166 259 234 1278 1017 1103 335 402 267 674 635 1309 649 1551 103 221 313 1030 8 503 523 727 326 337 628 702 122 1056 743 931 13 61 188 359 1090 1522 32 747 899 1500 386 432 54 350 677 907 407 1374 1268 1497 860 1134 662 960 1479 1583 129 532 170 1215 60 147 38 656 106 930 16 295 1022 1400 32 1052 168 263 226 1305 352 1303 70 388 180 1198 119 863 189 268 1553 1595 588 850 461 528 244 637 55 451 1409 1525 218 457 1042 1053 597 701 553 715 129 390 61 106 104 493 521 858 70 575 975 1152 707 1642 405 1211 811 819 107 255 533 1646 87 208 91 795 59 75 241 243 1290 1652 228 1390 91 468 1090 1323 22 24 241 1098 302 837 90 184 301 369 758 1183 271 349 457 1471 107 871 53 152 197 …
Output: 26

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Secret roads Longest Trail - MEDIUM Coding Problem | CodeTikki