CT42417

Last tunnels of Amara

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the thorn maze of Bramblecourt, Amara the cartographer keeps careful count of the tunnels. Price the new merchandise line, every figure matters. 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 <= 2187; the input is a connected tree.

Example 1:

Input: 1987 1060 1148 14 81 1416 1850 1312 1835 794 1792 463 507 61 1072 694 897 1 2 31 1425 985 1197 906 991 459 845 1504 1770 244 315 499 1651 1179 1923 650 1062 34 57 940 1184 827 850 401 655 616 695 238 768 99 139 378 924 741 938 401 594 155 489 164 1579 209 227 259 445 270 487 1367 1758 410 1211 51 269 606 676 806 1179 71 158 858 1933 730 1261 288 799 462 1855 118 916 7 106 1066 1120 1626 1898 86 289 420 830 523 654 415 1267 93 96 21 49 1337 1722 51 394 265 743 7 214 1266 1471 681 1124 175 1800 809 1580 536 1210 415 832 909 1650 1453 1502 1188 1345 104 123 223 673 1318 1808 586 1327 1015 1360 708 1127 278 451 497 1603 327 645 1047 1349 1430 1558 79 532 94 1810 99 677 1414 1474 907 1275 93 1215 689 1238 37 808 244 449 64 67 455 675 127 156 148 161 104 998 487 1006 45 202 32 61 1112 1786 130 1…
Output: 28

Example 2:

Input: 276 42 66 139 143 73 265 58 105 23 123 30 151 56 200 35 37 22 224 100 145 8 76 4 6 87 107 71 103 19 22 93 121 47 141 5 21 6 8 19 65 44 88 66 262 63 77 69 126 12 219 17 49 91 112 54 114 74 261 58 119 7 120 105 180 50 60 30 40 46 106 128 272 17 136 162 220 4 7 69 72 40 148 29 36 129 198 5 12 86 214 130 275 90 150 35 90 9 29 24 99 13 129 84 130 178 263 127 164 63 67 243 251 53 122 7 9 99 139 21 46 24 171 10 39 20 27 7 181 42 247 92 144 60 246 38 140 115 228 116 190 7 24 166 192 124 231 12 19 3 59 74 270 21 182 170 191 33 56 40 57 27 41 62 132 41 51 197 205 50 127 25 54 40 117 26 206 137 210 34 64 66 74 101 165 197 229 20 30 23 50 106 197 104 266 201 273 179 227 57 81 46 213 1 201 26 34 77 83 45 92 92 218 51 264 69 82 37 58 175 184 35 42 40 45 24 25 16 183 76 195 37 155 41 44 66 196 6 13 89 18…
Output: 19

Example 3:

Input: 933 23 213 309 560 120 131 127 554 295 415 53 741 137 153 426 570 165 877 193 336 70 292 327 492 127 594 207 300 517 608 652 865 283 523 22 41 452 658 237 556 373 864 27 471 77 320 100 557 251 589 158 527 55 367 125 184 91 341 45 87 204 340 146 659 462 678 358 466 53 270 237 339 442 836 127 171 46 250 65 668 357 687 133 141 362 686 256 283 210 303 287 430 87 786 208 217 5 9 136 692 548 635 50 70 147 548 79 421 262 448 692 738 76 645 411 824 234 264 156 188 129 909 621 838 474 585 388 871 620 760 431 670 456 883 92 242 130 682 263 423 104 517 121 509 285 491 81 262 572 742 356 787 2 203 64 83 504 574 392 438 82 386 52 103 13 26 270 414 47 52 61 881 293 422 11 235 42 175 718 855 802 869 158 186 678 775 67 209 36 197 492 567 43 289 58 63 504 926 364 532 329 618 268 850 521 580 94 204 423 533 …
Output: 23

Constraints:

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

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