CT47727

Finn's roads Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the foggy moor of Greyfen pays by the answer, and Finn intends to earn it. First: the full register of roads. 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 <= 3590; the input is a connected tree.

Example 1:

Input: 2642 684 722 882 1505 405 2037 132 1744 805 820 944 2104 605 998 164 2178 1390 1580 29 1753 107 191 1601 1876 359 490 327 1031 207 575 1303 2505 1193 1449 1878 1895 247 317 312 2082 48 766 974 1419 1031 1653 127 699 819 1192 257 2044 558 799 2051 2339 330 705 468 930 1844 2571 886 2039 375 547 1003 1556 35 585 377 2057 593 708 51 357 227 964 60 1785 321 2624 1058 1868 49 1061 1148 2312 835 1075 90 340 345 1313 1953 2298 451 453 424 582 1438 1708 703 1516 627 1148 745 2595 445 2248 988 2296 750 2151 447 466 110 152 872 1630 179 2493 176 2211 605 1437 1514 2476 1809 2229 218 2235 31 1339 325 1085 249 440 2459 2491 1023 2586 1392 1536 35 214 265 272 90 579 4 11 1946 1984 1992 2130 362 622 108 1365 31 119 2168 2474 651 1577 100 510 527 1064 48 362 1010 2400 838 1552 60 268 321 2159 1262 2013 5…
Output: 30

Example 2:

Input: 619 11 80 207 263 47 52 2 4 60 431 141 297 133 367 192 205 103 400 19 38 357 389 229 459 8 134 85 350 17 266 20 225 198 210 286 565 63 98 39 59 60 543 129 375 42 307 189 287 412 416 77 86 438 581 131 188 6 94 53 61 166 200 20 141 170 211 91 253 88 100 67 87 8 587 9 30 332 373 28 458 202 551 6 101 418 539 76 156 270 390 322 532 273 435 19 533 370 515 10 50 83 172 307 335 151 380 17 71 58 102 130 246 75 157 134 149 135 484 326 530 99 302 2 17 51 112 33 133 35 99 362 444 326 536 527 615 282 456 319 374 408 415 177 430 10 140 9 20 3 10 265 468 547 592 129 138 392 412 11 23 10 25 77 132 66 241 49 145 308 401 68 325 374 422 9 12 413 433 46 583 249 566 262 537 40 73 166 196 123 194 150 518 295 383 440 571 80 179 162 460 114 233 21 79 38 155 111 293 240 454 49 147 109 377 2 616 24 262 139 209 59 5…
Output: 25

Example 3:

Input: 452 39 48 201 408 3 236 8 361 34 306 99 287 7 51 134 263 136 395 21 430 1 45 136 152 14 67 40 52 12 99 308 407 19 25 85 130 88 109 3 4 168 221 43 356 63 101 107 398 20 93 67 77 215 258 53 57 6 8 39 451 96 415 85 88 149 188 121 229 91 166 71 181 80 440 171 376 149 439 40 103 26 216 9 30 55 303 24 137 24 146 229 242 112 424 17 69 38 61 203 334 77 298 183 186 39 362 273 372 54 201 181 226 45 158 148 370 22 92 63 392 51 123 229 261 130 419 21 34 1 41 39 64 166 170 87 91 105 147 23 29 207 227 23 358 72 270 153 172 206 237 3 86 12 46 195 438 27 121 6 252 21 22 232 329 263 284 304 383 62 159 170 346 9 58 239 355 368 446 183 301 28 114 108 120 35 180 21 26 108 122 173 243 66 278 225 380 58 139 24 50 189 304 267 340 89 100 199 312 88 90 258 385 102 386 54 433 298 443 185 399 31 267 195 435 40 369 2…
Output: 22

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Finn's roads Reckoning - MEDIUM Coding Problem | CodeTikki