CT48025

The Longest Trail of the Golden tunnels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the dune sea of Caravanrest. Ishaan spreads the tunnels 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 <= 1283; the input is a connected tree.

Example 1:

Input: 753 405 555 79 149 469 489 101 137 4 7 61 79 533 630 240 443 428 556 342 628 202 502 606 618 8 14 127 174 146 586 334 664 143 457 56 357 23 63 464 650 32 239 49 62 33 476 115 119 19 51 24 176 51 74 343 369 106 151 5 11 30 64 103 141 504 536 38 337 259 687 185 689 295 300 148 248 249 475 117 121 32 415 322 720 1 122 508 588 480 554 93 292 2 53 113 631 75 77 132 482 325 418 315 632 58 721 22 25 157 163 23 233 68 312 49 218 24 306 13 404 139 192 61 65 278 737 309 499 80 103 315 627 364 590 110 135 150 314 178 531 91 310 168 573 7 83 76 662 58 184 81 368 473 636 9 49 39 167 182 688 207 515 213 386 284 407 30 227 22 365 21 150 149 255 42 86 241 619 126 214 18 47 299 350 123 224 7 692 6 549 129 275 488 738 83 88 56 76 137 169 21 24 635 671 142 384 665 734 537 546 310 576 6 8 113 127 14 28 39 695…
Output: 24

Example 2:

Input: 1237 57 517 1181 1214 318 1205 138 561 7 23 104 1174 40 74 663 845 290 769 127 918 154 202 320 445 149 396 71 893 404 760 475 996 18 45 106 168 642 963 606 714 917 985 23 1212 65 254 313 863 132 577 771 1094 543 728 734 773 967 1055 810 1049 78 596 423 518 268 741 108 471 85 395 276 308 26 114 656 797 589 752 237 264 30 204 387 900 522 1165 762 794 39 940 833 928 292 1072 968 1060 12 55 328 1141 67 166 434 846 16 1198 188 469 129 145 4 78 6 9 171 431 106 235 95 251 218 680 1 245 250 337 723 1204 152 222 930 1093 37 480 2 3 516 634 139 255 676 687 589 804 223 246 612 1033 811 958 104 322 7 406 28 51 45 127 38 108 721 933 36 1114 525 705 1061 1197 569 572 535 1092 162 283 40 150 84 382 2 130 108 109 283 799 443 692 388 908 4 21 5 121 160 339 963 1216 286 307 70 363 124 153 31 632 97 112 188 …
Output: 25

Example 3:

Input: 288 64 105 4 37 42 46 5 57 69 159 70 275 9 48 42 69 3 107 52 115 79 99 15 216 183 255 37 113 143 156 1 4 25 286 219 237 3 259 30 39 60 253 96 287 108 121 8 15 42 100 9 58 60 119 15 43 74 220 85 93 207 282 138 203 126 218 190 250 34 41 185 249 124 178 8 142 52 81 35 42 22 23 1 3 1 5 71 75 107 256 126 163 102 143 7 9 190 264 58 64 141 222 195 224 98 213 16 17 166 245 49 181 3 94 76 148 128 177 7 8 49 147 107 200 110 133 187 239 154 240 150 243 55 71 112 228 136 185 8 173 22 235 106 134 54 234 156 260 185 208 68 192 39 54 204 238 40 165 26 197 141 195 78 96 134 199 110 117 39 146 34 135 29 118 65 109 119 175 149 233 171 202 3 14 131 183 20 205 13 21 17 28 218 261 87 254 41 112 13 172 113 209 34 51 210 273 25 27 33 55 5 6 43 82 27 32 156 263 94 140 193 244 70 130 149 182 23 126 82 87 27 129 43…
Output: 19

Constraints:

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

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