CT53876

Zoravar's bridges Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the lakeside town of Mirrormere pays by the answer, and Zoravar intends to earn it. First: the full register of bridges. 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 <= 1656; the input is a connected tree.

Example 1:

Input: 1321 516 806 143 803 57 504 265 792 316 398 4 68 5 51 177 311 109 382 26 117 125 160 582 1186 475 831 93 224 667 732 452 1251 564 1284 326 422 162 471 148 1099 74 598 927 1297 647 717 229 454 425 735 71 305 54 89 45 1149 521 601 115 1060 60 122 249 1057 244 1207 800 871 244 658 221 751 361 447 397 837 117 517 749 862 3 531 19 36 570 675 269 1193 145 156 34 734 963 998 136 1078 443 626 194 1205 133 274 193 973 143 193 309 581 387 961 584 817 717 1035 313 864 4 329 734 1209 97 171 127 157 19 70 337 462 476 564 366 1172 214 1080 13 39 120 283 648 1222 47 510 458 620 28 58 624 1321 463 592 397 710 369 957 406 825 359 1294 282 335 7 271 37 420 618 980 70 75 624 1046 130 132 809 1296 50 1073 807 878 253 1100 12 14 578 989 112 853 576 585 293 552 62 277 562 687 29 655 734 811 431 855 280 834 28 1…
Output: 28

Example 2:

Input: 1142 116 183 17 206 482 721 406 748 273 1096 699 797 65 79 266 429 370 543 650 745 274 368 687 833 932 1055 372 394 39 871 490 676 731 966 76 253 50 268 545 937 336 430 289 834 66 223 7 14 31 924 5 840 217 290 183 1093 52 99 435 640 494 945 7 13 175 536 289 484 157 350 136 151 359 501 875 895 898 951 19 286 189 210 187 545 20 22 153 246 340 357 826 955 379 557 338 697 488 532 200 212 7 629 10 562 277 1105 152 617 413 427 296 1116 834 1141 35 478 305 309 523 896 913 946 525 863 16 44 16 58 477 496 8 74 76 319 36 374 31 229 951 1079 352 1073 50 174 420 892 484 491 80 598 501 836 411 980 148 315 390 1104 237 971 574 1012 514 718 1011 1013 34 262 73 197 415 661 515 828 136 839 228 984 73 83 79 887 827 1053 76 208 154 1044 166 679 290 1138 436 989 736 930 251 957 268 962 365 605 49 53 281 832 6…
Output: 24

Example 3:

Input: 206 56 86 8 42 20 59 48 156 3 189 30 32 58 62 4 27 126 202 133 173 17 23 33 200 55 58 24 30 15 96 95 198 111 180 117 187 34 160 92 131 22 25 57 61 119 193 55 195 2 11 68 76 149 174 85 182 77 178 14 34 69 203 5 8 2 5 9 24 142 150 99 199 39 56 53 110 98 143 100 120 69 77 71 142 24 29 7 48 1 118 54 129 165 166 153 184 47 148 23 98 56 90 3 16 111 185 65 102 134 158 44 159 2 19 19 171 12 179 4 17 2 93 69 121 21 55 101 191 20 167 7 107 19 186 26 54 58 75 103 111 79 116 87 154 25 64 35 87 23 82 98 181 53 69 41 190 33 51 103 115 97 141 31 60 50 92 30 105 46 138 5 38 88 132 27 99 162 194 19 126 108 114 85 176 51 144 36 165 149 197 131 183 65 84 6 21 16 50 10 14 26 74 44 117 87 155 73 88 5 41 70 71 25 146 2 7 81 151 18 33 65 67 80 127 33 35 40 46 16 52 124 201 83 175 34 65 36 172 23 78 80 153 23 119…
Output: 17

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Zoravar's bridges Reckoning - MEDIUM Coding Problem | CodeTikki