CT36491

The Longest Trail of Tuskmore

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the boar woods of Tuskmore pays by the answer, and Farhan intends to earn it. First: the full register of tunnels. 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 <= 1782; the input is a connected tree.

Example 1:

Input: 928 568 622 409 725 61 823 13 167 228 847 738 779 853 855 83 218 287 531 49 377 577 793 257 360 161 203 558 563 209 422 697 905 308 427 537 568 198 341 149 433 472 653 254 620 483 501 123 647 150 260 310 719 167 764 584 832 98 809 19 113 393 396 117 227 696 883 18 322 73 228 219 400 539 640 147 304 294 468 58 452 318 532 325 856 132 196 160 704 632 676 495 666 731 787 14 636 352 530 371 546 678 908 5 7 185 556 140 655 133 459 344 679 15 110 17 51 632 718 157 453 66 222 96 122 165 511 129 373 104 197 66 922 8 444 467 765 128 839 341 564 211 573 408 584 5 34 46 111 311 775 56 210 294 525 62 118 6 11 238 476 157 287 19 77 73 674 316 388 116 198 91 155 236 393 16 21 227 713 713 919 408 535 251 469 70 624 131 211 56 60 11 195 417 752 24 69 8 904 84 589 416 788 131 164 261 581 78 552 194 715 15 …
Output: 24

Example 2:

Input: 404 40 294 70 141 187 258 26 28 238 256 186 357 151 358 42 106 15 237 211 279 63 158 24 53 33 140 243 330 41 302 30 276 64 289 15 33 150 249 100 316 32 274 30 93 153 196 147 167 179 285 253 334 17 38 8 17 190 320 100 171 196 220 139 179 35 365 221 263 11 342 49 121 326 347 5 44 234 375 13 59 73 147 46 108 159 377 163 208 22 89 195 266 1 2 57 273 230 401 315 389 204 313 42 185 1 31 118 290 339 395 74 355 89 118 291 388 125 200 30 79 54 176 152 190 286 385 3 6 77 216 174 180 197 392 36 307 16 39 4 86 42 259 265 398 5 27 5 37 101 104 106 399 195 270 40 107 290 337 162 239 103 262 47 75 95 235 124 384 100 136 264 327 279 295 190 368 278 308 16 22 4 243 114 129 12 13 156 246 70 194 83 321 66 119 21 172 2 8 244 363 59 187 42 153 46 103 80 338 63 370 155 247 15 160 66 207 153 394 6 127 8 269 93 2…
Output: 23

Example 3:

Input: 1313 173 762 1027 1117 39 118 602 977 1027 1143 160 1099 362 437 64 422 1 275 300 403 9 897 1127 1284 14 35 202 941 314 427 609 867 542 773 208 400 780 1070 267 391 277 735 87 178 2 5 1043 1116 62 1246 130 869 121 944 6 1297 413 548 8 203 420 870 262 855 86 179 405 1106 223 240 29 54 111 170 281 981 143 524 278 568 442 808 525 1204 1 64 768 1268 13 26 738 1009 1014 1212 201 903 174 200 635 1162 391 705 188 971 242 1171 186 315 301 387 848 1105 295 937 31 356 132 1283 461 713 829 1275 279 313 1116 1126 935 1182 621 1154 430 594 290 325 469 631 221 324 296 792 502 541 425 459 533 1084 136 642 61 402 346 759 120 656 559 809 81 83 178 199 605 647 430 710 36 225 733 851 196 241 54 65 368 470 129 673 152 294 209 260 635 965 471 478 176 675 209 244 309 610 183 202 148 152 956 962 4 1161 488 604 1…
Output: 24

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Longest Trail of Tuskmore - MEDIUM Coding Problem | CodeTikki