CT48192

The Longest Trail of the Prismatic corridors

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the ember mines of Cindercrag. Esha spreads the corridors records across the table and picks up a sharp pencil. 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 <= 1543; the input is a connected tree.

Example 1:

Input: 545 92 294 63 510 35 267 136 213 443 516 84 85 421 451 67 83 215 216 193 397 91 197 35 256 216 439 51 179 281 382 80 159 117 187 67 275 29 161 32 410 10 104 104 107 1 201 18 246 15 23 68 212 50 245 105 129 36 391 6 316 27 36 23 42 65 180 380 443 86 167 190 491 294 444 18 373 19 170 194 319 2 4 516 517 2 38 176 209 120 137 97 203 146 158 161 286 159 301 89 183 72 545 317 473 135 241 278 383 266 299 25 29 27 173 222 264 140 378 74 194 387 500 8 10 141 449 52 193 286 539 36 447 3 8 66 76 146 296 87 228 275 476 23 168 144 536 221 427 4 9 24 150 5 70 276 523 160 211 11 163 25 218 79 430 148 152 90 454 92 102 299 453 121 131 11 53 19 24 299 398 416 475 18 130 226 261 10 119 7 176 267 276 76 86 27 353 99 224 201 409 421 426 202 537 309 360 414 494 176 222 291 479 137 478 70 362 282 541 10 11 164 …
Output: 24

Example 2:

Input: 1183 85 204 78 161 538 673 349 398 40 378 874 1160 128 213 16 22 48 949 8 1075 259 1109 197 615 382 583 21 407 631 1022 48 364 381 428 220 266 194 211 358 467 129 753 108 127 70 104 368 1087 129 235 676 681 197 687 955 1144 243 468 933 1050 350 1171 366 576 418 1170 78 762 132 1125 632 806 38 172 616 1041 239 1057 182 483 200 507 41 1126 207 1104 151 355 176 1154 147 412 262 430 502 870 366 676 56 666 25 54 157 405 8 120 243 670 394 961 299 354 49 306 201 372 158 741 624 1007 130 238 6 94 609 896 316 384 866 909 272 392 292 763 11 38 167 297 252 296 84 1044 614 994 317 370 244 393 48 707 305 1168 313 605 357 637 350 1049 174 944 255 563 475 515 87 632 565 876 53 175 361 1061 36 114 199 1137 18 75 83 619 425 709 714 893 725 890 360 540 463 974 90 293 269 777 735 849 2 13 133 196 4 67 74 135…
Output: 29

Example 3:

Input: 1109 120 131 350 433 4 5 172 732 83 950 229 849 109 115 308 437 101 998 89 219 555 685 155 185 82 597 282 390 139 270 261 562 1098 1101 2 43 70 173 2 9 61 77 33 261 233 319 262 521 176 481 365 412 613 821 115 139 218 657 138 353 20 282 49 80 446 448 429 639 163 618 172 1001 165 237 634 1052 413 471 172 680 231 339 87 693 406 796 98 615 653 744 2 1092 92 410 877 1091 1049 1069 140 745 166 938 3 17 340 1025 9 45 318 482 31 52 68 857 921 1096 70 292 28 95 6 454 23 228 440 992 267 531 164 191 648 658 278 584 19 35 948 1038 514 588 151 808 17 116 424 634 71 316 353 358 4 859 514 626 4 733 85 456 36 575 791 971 57 100 223 396 160 537 591 790 248 1043 497 1086 32 76 303 402 68 716 238 386 171 1058 18 359 38 85 37 253 146 395 400 1105 102 144 234 276 65 73 289 710 630 1002 114 930 158 559 810 1012…
Output: 29

Constraints:

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

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