CT50016

Amara and the Dusky corridors

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the ember mines of Cindercrag, Amara studies rows of corridors entries. One clean number will settle the guild's oldest argument. 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 <= 2504; the input is a connected tree.

Example 1:

Input: 450 171 256 11 26 190 398 79 147 130 281 74 164 184 261 183 197 24 61 12 14 86 436 64 185 285 385 32 70 18 33 1 356 293 341 6 9 49 342 56 139 295 339 31 117 30 437 233 299 138 293 212 226 361 439 266 435 30 104 133 150 30 90 195 238 254 393 237 370 68 81 36 89 99 168 201 311 135 146 344 389 205 253 33 301 25 82 70 171 1 34 106 395 263 265 26 320 164 278 8 84 242 414 44 77 371 372 35 274 64 133 255 348 97 260 202 357 75 241 1 279 211 345 11 196 58 128 234 438 60 286 150 404 30 144 20 96 1 2 273 284 24 28 8 31 17 447 102 287 43 78 165 184 62 300 84 262 164 205 46 53 165 354 21 445 58 306 30 443 5 303 83 193 64 223 153 176 113 314 28 63 8 15 25 165 84 308 83 166 243 379 212 353 34 214 120 246 249 338 161 444 102 177 50 210 54 73 57 368 4 13 2 3 9 124 40 72 198 363 287 309 231 390 90 229 62 68…
Output: 22

Example 2:

Input: 2172 1824 1907 1247 1863 808 1335 365 766 67 185 899 1639 1278 1873 34 769 1216 1285 1463 1594 1410 1843 7 1491 2075 2161 1376 2076 643 2102 48 215 55 492 407 2018 208 1697 544 782 769 2088 305 828 124 287 1983 2126 519 581 525 1277 465 884 1200 1745 375 400 15 957 402 1881 103 229 1352 1895 604 837 848 1445 851 1533 253 559 63 1306 542 1712 1372 1386 763 1197 8 11 1992 2067 280 315 941 1641 299 349 585 988 1123 1802 1221 2109 895 1001 165 1988 585 872 1209 1504 571 1066 93 1034 1451 1679 687 1804 704 903 899 1520 852 914 70 100 1559 2147 922 1776 1779 1847 747 911 1059 1528 422 739 257 460 295 939 691 1096 1092 2051 4 257 645 649 66 767 913 1511 60 137 1311 2130 175 1273 770 844 609 821 246 799 592 1118 190 949 1561 1618 548 711 102 763 665 1043 1114 1725 1013 1577 450 1459 172 1996 1191 …
Output: 25

Example 3:

Input: 9 1 5 4 8 5 7 2 9 2 4 1 2 2 3 4 6
Output: 5

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.