CT42870

Envoy's Ledger of corridors

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the floating docks of Skyharbor; Envoy weighs the day's corridors 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 <= 3943; the input is a connected tree.

Example 1:

Input: 1128 18 183 218 263 373 462 356 833 282 727 310 702 109 442 57 740 129 328 98 900 241 707 230 498 704 849 72 173 409 612 502 904 4 958 199 908 287 402 142 240 150 219 351 400 88 133 143 1048 6 300 687 1021 345 388 13 213 381 718 222 772 419 683 500 1088 612 845 646 775 284 492 294 827 283 776 308 450 531 1007 121 294 281 1076 191 363 282 560 410 656 381 943 354 774 60 621 651 920 614 753 463 486 63 225 54 78 131 154 635 846 600 670 435 1095 110 282 279 283 222 607 22 99 309 687 142 258 94 260 189 250 25 193 58 70 32 73 554 757 981 1034 199 269 598 794 230 343 356 641 72 302 215 743 106 226 50 552 82 206 115 179 236 429 137 459 575 1082 636 1056 770 1017 38 752 10 43 123 168 338 519 460 973 74 97 470 993 725 1000 71 410 500 1038 14 54 215 1023 296 396 148 221 429 960 73 324 670 677 1006 105…
Output: 23

Example 2:

Input: 1294 597 913 515 1131 386 539 339 1230 1017 1232 428 617 98 861 541 830 333 682 3 7 311 387 386 1028 20 282 538 1174 367 1163 569 992 92 461 263 877 101 574 12 403 494 1187 790 837 375 686 425 436 254 603 565 1125 645 964 174 590 541 858 723 951 83 271 4 14 60 209 146 662 163 641 649 705 651 771 125 169 238 1074 35 360 122 914 271 620 455 648 753 759 313 1050 14 477 48 205 976 1087 289 519 7 240 411 495 786 801 38 84 755 849 206 227 949 1247 25 506 26 1193 657 906 388 1072 820 1177 3 94 62 76 534 577 299 421 745 783 31 71 189 480 55 984 16 22 433 505 187 1127 354 388 156 328 792 969 189 487 12 85 115 826 10 133 874 939 13 125 127 310 494 589 134 381 594 741 2 44 9 304 777 1235 95 112 483 949 631 1265 555 870 14 120 486 806 11 177 413 419 6 46 636 1273 112 441 590 1049 24 268 642 677 47 840…
Output: 27

Example 3:

Input: 1595 442 592 281 1503 153 634 201 666 736 751 664 677 325 658 75 1047 159 581 637 1065 146 271 157 195 336 1524 403 512 478 1258 799 850 59 638 205 689 876 1098 13 293 336 346 475 1172 79 508 195 1499 1505 1568 89 586 76 988 1266 1569 57 172 894 1413 664 1530 29 676 34 891 657 1522 930 1334 650 1431 103 158 196 820 1369 1581 2 74 133 142 1237 1326 395 436 791 1046 817 1478 266 1040 91 211 99 157 173 333 754 1507 617 1127 579 1441 864 1131 857 1110 184 652 195 627 29 71 966 1084 141 145 555 965 198 201 889 975 716 1115 563 806 199 1468 328 712 18 76 854 925 1070 1214 9 94 934 1033 537 1433 104 1300 642 1393 257 367 124 1255 1054 1549 896 1076 246 1198 325 635 415 462 274 764 93 163 1182 1186 521 897 895 1058 237 857 1127 1462 172 175 108 563 958 1432 226 443 417 847 46 1180 243 338 469 777 …
Output: 30

Constraints:

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

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