CT51983

Manav and the Gleaming bridges

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the bamboo terraces of Verdantstep, Manav records each bridges 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 <= 3907; the input is a connected tree.

Example 1:

Input: 1695 224 864 313 767 368 568 33 881 236 1153 605 809 326 1191 414 1031 209 1325 655 1133 149 437 102 133 291 343 515 631 465 634 373 696 249 482 232 852 711 956 204 851 4 554 137 1429 511 917 1241 1305 231 1255 147 973 1508 1624 901 962 159 268 819 1251 93 378 362 766 315 1320 40 108 185 1570 254 1664 1117 1214 480 1075 18 19 205 468 235 300 243 432 559 1470 195 517 858 1627 47 312 754 1003 98 332 139 253 6 1094 145 157 1246 1276 92 346 677 762 375 968 157 1048 156 163 39 327 858 1671 1242 1283 213 691 200 537 262 643 1263 1628 780 1500 20 490 144 958 900 1088 1075 1228 719 922 1169 1439 776 978 239 583 586 799 304 1324 237 746 4 26 765 1435 604 819 442 798 77 106 167 832 280 1292 316 1377 329 416 132 209 750 1010 438 905 434 874 287 995 228 406 453 1618 1672 1684 816 1270 68 201 141 158 4…
Output: 25

Example 2:

Input: 1482 255 421 601 634 677 1418 491 577 1400 1430 939 1183 989 1087 1 686 788 1043 1128 1159 473 1270 140 841 165 269 11 395 199 259 265 459 101 173 24 141 496 1384 884 1422 366 453 264 287 6 31 171 1103 177 832 101 718 174 717 335 1032 859 1198 638 974 144 774 437 534 240 1288 30 399 17 432 89 809 229 1367 862 1419 252 446 657 765 437 940 276 699 514 1388 657 1373 504 988 598 601 135 1223 128 204 1023 1310 246 563 459 506 137 981 500 520 43 84 217 261 158 903 43 181 564 691 21 153 10 528 93 121 478 1021 1050 1298 138 480 755 927 420 1214 1090 1266 19 1115 78 221 15 30 1107 1208 147 1332 843 1092 949 965 257 341 508 942 1 112 836 1101 365 1124 6 292 27 272 1162 1215 20 383 313 1245 86 195 922 1358 149 1263 123 330 79 1058 119 322 7 10 538 658 190 1191 132 576 110 991 482 508 287 608 337 1315…
Output: 33

Example 3:

Input: 3012 842 1240 214 961 89 1136 999 2134 1922 2399 915 1686 345 2804 129 510 54 310 1 2 436 580 956 1054 2145 2682 359 722 1218 2699 1355 2712 1713 2596 149 816 120 771 2115 2548 764 923 1139 2885 1582 2924 1081 1868 467 1055 997 2431 705 2731 287 546 758 1914 1881 2150 1114 1955 1140 1929 39 89 68 2130 844 910 19 263 1077 1478 5 33 420 1550 1386 1510 637 1308 384 628 703 1828 201 444 556 1197 838 1543 2338 2655 1066 1847 1135 1951 331 680 600 2781 161 889 775 1008 258 879 1848 2583 643 2205 1175 1290 528 949 2049 2371 382 432 8 171 1439 2652 312 558 1944 2038 164 2766 434 579 2028 2775 1647 2097 1376 1467 1952 2080 1925 2117 737 876 510 1069 2067 2178 247 1194 288 1283 63 675 1090 2986 383 2331 951 1066 830 1163 202 421 320 870 370 2248 945 1320 245 303 137 1496 1449 1453 291 1461 1073 2008…
Output: 26

Constraints:

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

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