CT42234

Nyssa's corridors Longest Trail

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the ember dunes of Ashfall close for winter, Nyssa must finish the corridors ledger - one figure at a time. 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 <= 1125; the input is a connected tree.

Example 1:

Input: 1020 6 45 157 774 62 74 77 658 360 600 471 636 669 713 247 425 708 849 215 642 56 124 453 507 127 940 2 3 25 149 560 749 708 754 440 914 16 21 321 978 9 645 160 846 469 595 733 811 369 932 521 974 291 486 728 924 200 602 42 521 144 187 361 1008 602 708 375 429 3 60 38 668 6 85 678 807 406 570 78 492 143 641 470 599 370 393 299 694 450 605 217 288 381 883 194 444 25 674 150 333 327 927 421 535 135 176 214 226 701 745 326 500 239 789 4 62 403 941 127 147 174 824 262 476 51 911 682 939 36 245 522 592 30 81 155 263 109 132 240 537 457 714 252 571 341 491 296 579 170 234 369 461 127 383 157 896 829 915 13 17 173 195 75 118 710 798 134 302 119 567 97 211 25 438 177 505 367 879 607 943 7 23 362 407 299 944 419 833 82 136 75 741 6 112 775 966 212 748 328 473 208 323 57 75 197 931 167 326 89 208 16…
Output: 24

Example 2:

Input: 318 111 277 172 188 127 267 12 40 26 89 303 316 9 45 105 158 201 248 15 112 13 39 93 245 17 19 45 196 178 190 5 22 207 221 274 315 94 232 56 101 121 131 5 16 30 36 162 178 45 259 76 202 4 35 188 203 89 282 66 147 3 8 80 215 122 129 199 314 112 191 41 134 207 244 49 160 130 181 198 254 7 21 40 107 4 66 10 212 72 87 86 99 66 114 39 299 149 318 11 41 29 173 29 118 151 168 157 170 53 55 101 260 31 116 21 59 43 91 10 269 56 234 89 166 8 17 28 43 75 298 125 159 2 11 61 206 131 301 240 293 25 156 62 76 119 218 98 119 276 297 117 126 45 146 106 280 136 204 58 60 58 109 62 295 34 222 127 133 35 42 14 20 49 278 213 217 51 286 46 236 147 210 41 180 84 281 51 69 53 61 21 88 68 268 196 238 32 74 232 240 1 2 20 37 94 199 23 288 27 185 39 194 16 81 120 172 44 309 50 92 181 265 146 189 182 198 45 82 22 38…
Output: 22

Example 3:

Input: 493 36 183 76 132 85 125 7 482 220 265 160 408 363 410 14 101 28 77 49 89 115 122 67 399 113 448 8 298 11 12 96 221 66 405 149 274 23 64 41 200 76 195 419 426 61 66 140 229 46 251 90 163 9 306 222 232 289 380 299 316 140 218 306 368 66 152 54 149 34 46 205 403 443 490 103 171 239 351 33 239 342 419 61 305 27 53 4 321 88 123 31 443 86 118 143 336 10 373 10 386 243 324 169 226 29 438 110 133 137 285 252 372 89 245 320 388 103 165 124 292 59 442 71 167 11 24 197 278 214 406 83 201 335 375 53 457 68 73 74 150 96 110 46 104 54 279 121 349 222 471 90 156 104 303 55 98 77 193 94 462 6 80 111 134 151 257 318 434 67 241 258 473 105 338 99 393 21 96 124 398 5 176 326 394 103 258 2 4 42 492 138 319 261 421 20 23 152 288 82 194 118 418 46 299 66 224 73 97 327 485 179 182 155 230 127 347 11 446 217 325…
Output: 18

Constraints:

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

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