CT46396

Hugo's Ledger of corridors

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the mushroom groves of Fungaldeep opens only for a perfect tally of corridors. Hugo means to find out. 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 <= 2084; the input is a connected tree.

Example 1:

Input: 273 54 91 15 215 58 235 18 177 121 184 27 72 66 110 161 242 23 27 26 104 38 161 202 244 21 221 18 28 1 6 186 248 5 39 7 156 10 103 83 232 5 245 1 2 12 186 14 25 78 239 8 237 146 173 41 73 54 98 5 24 20 21 6 53 17 101 166 178 22 75 67 139 18 23 265 270 78 133 141 192 155 199 72 78 31 179 166 175 10 87 1 89 142 269 65 93 184 251 60 138 13 31 10 60 20 33 103 136 181 257 110 231 16 243 119 188 120 183 4 126 178 225 98 260 52 69 101 108 15 46 6 10 3 127 27 222 77 272 14 22 197 212 16 18 179 197 45 266 13 82 57 217 97 130 128 163 13 15 14 35 102 198 87 102 50 134 61 96 32 44 27 63 6 115 29 37 131 196 32 58 43 74 242 261 118 230 12 265 118 144 35 172 44 52 34 77 156 185 38 181 2 12 41 112 45 57 22 158 97 187 13 84 106 147 38 253 44 54 58 174 121 213 140 169 64 214 16 80 109 113 1 19 27 59 71 210 …
Output: 19

Example 2:

Input: 1705 688 1674 395 581 756 1375 86 654 977 1646 752 870 621 947 214 490 184 1422 566 580 1227 1256 450 629 512 851 114 183 39 391 378 1147 322 332 1145 1148 959 966 315 525 1074 1217 148 1500 139 392 743 745 334 590 257 1692 125 401 24 78 834 1059 12 722 866 1526 381 1184 268 445 730 1023 14 124 557 614 965 1336 18 295 243 255 1224 1558 68 208 159 555 994 1632 81 314 1198 1201 93 131 77 634 1263 1298 172 400 262 1137 202 928 173 551 821 1467 416 1439 130 203 486 750 264 970 364 467 89 412 1178 1582 33 1437 903 1695 44 221 12 998 30 33 1109 1547 53 272 376 469 1018 1160 521 1396 6 7 4 81 127 237 464 465 947 1389 1166 1552 568 1118 391 1179 223 735 539 594 187 405 3 924 456 858 40 218 67 243 525 645 288 967 73 121 1161 1216 877 1625 894 1187 477 499 746 767 277 605 12 291 892 1611 16 38 393 1…
Output: 25

Example 3:

Input: 809 190 442 273 312 354 589 304 594 45 58 466 743 78 606 96 419 277 622 258 560 382 408 404 561 86 137 299 649 50 67 104 191 191 675 198 523 99 210 42 757 303 555 92 224 80 318 97 382 2 3 38 298 10 63 69 127 684 750 20 197 45 146 77 286 268 422 7 22 18 91 152 178 56 78 487 737 444 470 471 735 338 391 94 642 115 237 20 114 6 464 151 508 322 407 28 79 309 651 94 310 201 653 270 439 361 671 502 621 155 168 367 377 160 169 285 701 65 175 51 359 179 697 144 736 198 287 424 646 209 277 122 424 155 227 257 345 15 53 58 134 339 652 208 515 270 747 130 623 72 150 211 268 87 250 544 800 30 432 9 16 29 102 13 37 47 705 68 427 413 495 230 717 29 450 579 687 443 668 557 704 225 304 4 247 193 667 123 300 137 385 588 774 13 71 37 282 159 239 390 488 5 23 537 557 491 584 399 639 17 216 36 142 385 461 69 1…
Output: 26

Constraints:

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

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