CT40822

Last corridors of Opal

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the mulberry rows of Silkmead, someone must prepare the expedition manifest. This year the task falls to Opal, armed only with the corridors register. 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 <= 1741; the input is a connected tree.

Example 1:

Input: 1179 131 387 352 880 142 1092 206 767 16 25 566 651 1009 1029 508 1132 121 220 168 479 60 87 4 777 21 38 192 239 341 569 2 503 251 751 136 711 117 342 200 545 260 322 686 784 170 385 145 648 259 395 89 203 120 126 68 397 422 710 271 836 36 499 141 447 877 977 170 277 441 1079 636 890 515 558 1019 1074 190 419 151 450 359 895 1032 1178 413 1151 274 293 139 553 265 282 222 331 157 1068 480 1064 561 822 11 60 34 831 30 45 242 846 74 1105 301 313 80 216 146 773 153 468 97 425 2 595 1018 1143 96 371 207 521 185 217 111 1005 136 1171 105 206 646 1160 1121 1166 90 565 180 223 116 950 107 137 474 748 5 75 40 1168 496 1104 9 51 169 933 428 957 139 625 562 805 125 284 496 1073 298 312 16 57 87 167 386 531 44 109 295 937 83 1015 71 1174 616 935 6 506 26 46 651 1139 148 341 224 279 400 1013 123 562 63…
Output: 24

Example 2:

Input: 25 14 15 15 25 17 20 2 3 7 9 11 22 4 7 14 17 2 6 2 13 6 10 20 24 1 2 4 18 1 5 12 14 2 4 3 8 12 16 4 19 1 21 8 23 7 12 1 11
Output: 10

Example 3:

Input: 1278 209 346 12 161 8 410 363 636 11 153 113 918 47 516 209 256 562 604 1174 1255 155 158 155 438 559 611 311 571 969 1242 703 1263 72 640 161 959 358 415 227 555 668 862 374 1143 156 166 415 657 421 495 438 475 610 625 237 591 1151 1160 3 9 1 1149 122 617 791 1076 20 255 577 808 277 537 484 676 1146 1226 888 1001 169 987 871 1103 393 1252 333 662 369 783 786 1206 828 974 84 116 81 171 148 246 264 465 205 366 8 19 101 393 354 1005 836 1146 386 773 740 887 928 1081 461 501 161 472 31 49 33 160 454 510 143 1166 97 739 17 701 366 1267 324 1241 112 496 19 173 280 317 125 174 582 778 12 420 247 334 106 226 629 779 624 899 5 6 229 1046 91 127 146 575 708 1269 59 840 771 1247 65 451 28 53 422 1182 539 851 597 964 129 359 406 924 42 376 420 771 121 869 459 1187 314 1101 139 262 235 897 96 235 329 …
Output: 26

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Last corridors of Opal - MEDIUM Coding Problem | CodeTikki