CT53851

Uma's routes Longest Trail

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the cotton rows of Whitewick pays by the answer, and Uma intends to earn it. First: the full register of routes. 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 <= 3538; the input is a connected tree.

Example 1:

Input: 278 29 101 81 249 72 129 110 161 241 244 14 34 15 54 166 189 126 180 47 275 79 127 35 47 55 81 83 121 14 223 111 233 27 77 28 124 110 207 97 123 185 205 3 5 6 142 115 238 3 91 54 65 20 38 1 68 15 17 167 229 50 106 59 159 81 267 3 6 233 263 86 222 63 204 60 221 22 36 6 102 22 88 42 69 29 167 6 74 20 198 102 268 1 2 82 113 82 152 157 176 138 260 5 14 57 115 18 125 160 199 13 186 12 15 85 218 117 232 82 96 51 192 50 95 126 130 22 174 70 197 6 169 146 246 5 147 24 41 97 212 108 135 146 230 68 87 72 86 15 273 12 188 40 45 4 140 106 166 161 168 73 193 61 92 30 181 3 21 97 162 164 278 95 128 174 200 169 256 5 114 160 185 64 270 12 51 183 191 88 93 29 49 158 202 6 83 32 53 55 241 235 237 9 13 10 97 158 236 55 226 81 84 8 31 25 42 104 231 166 227 70 79 14 35 21 24 90 145 82 156 64 98 42 154 7 10 23…
Output: 17

Example 2:

Input: 895 446 482 218 839 421 527 212 817 275 793 34 806 224 406 109 278 427 483 338 738 546 709 52 119 66 92 239 428 387 770 15 508 498 591 161 188 318 548 125 822 159 297 82 160 163 627 188 882 600 710 24 58 277 359 45 50 217 333 182 187 36 163 122 270 233 420 796 894 172 660 690 718 511 761 12 266 73 276 142 440 57 568 167 169 348 612 502 755 234 506 153 238 14 400 169 749 143 478 254 327 114 171 499 652 409 421 39 113 827 870 190 639 189 331 143 460 97 479 49 524 525 688 31 66 147 192 54 564 22 154 422 767 547 769 287 635 130 466 440 700 142 683 70 387 814 878 244 500 161 260 725 729 35 37 165 690 82 671 387 396 141 435 18 75 586 696 36 251 42 262 768 891 101 336 115 530 38 789 249 602 116 821 355 494 209 803 163 176 26 190 208 354 11 34 357 499 362 374 153 802 356 673 190 711 507 557 30 391…
Output: 27

Example 3:

Input: 1117 144 392 313 840 224 369 52 336 790 950 804 1095 50 631 161 314 142 358 835 1000 30 637 400 471 915 1050 202 223 113 187 149 1010 31 42 938 1047 93 122 174 828 166 881 58 364 56 975 41 164 22 40 11 176 356 843 438 1031 275 870 377 1081 340 1049 383 412 264 408 882 957 166 537 258 587 7 18 331 442 596 900 382 456 860 871 9 48 12 57 58 1071 401 649 28 816 21 307 44 263 24 533 20 24 366 532 1043 1065 87 104 270 800 38 56 693 857 98 126 3 241 91 528 52 99 739 753 433 606 360 864 137 1103 449 707 145 476 133 822 196 954 148 1093 163 608 515 721 570 757 80 960 550 698 79 549 410 850 483 882 2 145 241 417 340 688 20 829 171 1020 62 319 760 1051 98 103 70 333 675 774 294 329 593 634 443 762 175 271 660 929 8 12 104 553 745 1057 23 522 462 761 83 1034 133 878 229 339 295 851 111 592 50 460 487 …
Output: 21

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Uma's routes Longest Trail - MEDIUM Coding Problem | CodeTikki