CT35813

The Longest Trail of the Azure roads

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The scribe Herald has been asked to prepare the expedition manifest. On the desk lies a long table of roads readings. 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 <= 2030; the input is a connected tree.

Example 1:

Input: 1527 53 169 616 1159 80 1425 28 610 136 194 312 1157 1138 1446 264 384 617 1020 739 1230 789 1223 875 1306 79 1411 540 1477 773 826 374 839 364 501 873 1192 79 225 9 16 20 916 648 1350 172 1211 755 856 234 1417 619 1250 266 432 18 45 611 745 290 763 26 362 569 687 379 634 214 473 458 760 340 387 201 587 180 698 1061 1237 187 296 108 360 1197 1426 1244 1490 10 88 1373 1402 1128 1420 836 921 194 1463 135 142 36 97 446 862 1162 1238 1049 1194 358 1342 126 315 306 590 4 34 1047 1488 137 526 1085 1129 422 1333 347 516 179 462 620 902 617 891 43 453 83 452 34 606 26 618 64 383 1385 1432 217 566 39 398 12 66 68 461 243 451 695 1119 604 1491 249 316 174 273 171 1051 57 710 102 221 429 608 1128 1285 639 726 195 694 1136 1472 181 236 598 705 634 640 1186 1485 246 556 143 1264 412 716 529 1033 32 131…
Output: 28

Example 2:

Input: 1678 470 1099 12 32 114 222 45 943 416 786 1073 1546 1024 1135 248 847 1350 1368 1437 1517 168 412 887 1323 448 1009 1189 1394 75 324 36 86 143 518 319 361 583 1447 65 709 1606 1678 712 1091 1056 1597 521 1335 1086 1141 330 378 422 778 850 1186 134 1523 302 1185 938 1048 111 578 88 575 176 1303 140 175 16 31 350 735 591 613 270 1124 323 611 585 1100 254 972 1276 1358 736 905 564 629 406 702 1606 1641 315 1103 287 294 142 163 87 368 1060 1311 572 989 361 440 232 1156 329 1228 1505 1650 884 1315 405 641 144 190 19 1322 248 1021 827 1670 71 77 15 27 169 194 403 1076 740 935 566 1151 832 1298 339 638 1057 1074 345 781 452 753 175 588 874 1463 81 335 222 586 87 413 134 261 697 1384 967 1320 306 589 75 635 302 1066 341 752 411 903 507 954 568 978 380 747 336 1306 612 1445 178 1122 1490 1586 783 …
Output: 27

Example 3:

Input: 1078 304 498 38 75 38 58 63 234 44 54 60 329 175 206 25 261 246 313 406 938 94 866 628 673 703 1010 78 458 259 696 18 125 281 1071 581 932 448 719 536 625 17 387 80 107 99 511 17 214 579 1024 363 419 50 200 314 432 32 113 306 645 7 541 119 789 131 586 39 126 408 889 79 127 57 821 28 354 92 155 230 333 525 659 446 962 585 614 248 277 625 649 13 20 487 691 63 273 72 193 458 553 51 852 55 245 87 258 421 611 305 921 305 533 199 299 612 888 807 958 25 520 353 406 300 766 87 491 59 104 25 485 650 1050 26 307 1014 1041 441 592 25 68 68 415 37 153 128 212 101 250 279 510 183 805 154 550 57 918 659 688 467 914 136 579 394 548 169 386 1018 1062 41 293 157 176 11 22 394 608 61 1032 91 362 133 835 277 296 428 773 8 72 529 797 379 528 118 317 299 699 22 618 28 332 246 829 158 184 360 1004 151 1034 524 …
Output: 27

Constraints:

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

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