CT53552

The Longest Trail of the Solar corridors

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Hestia runs the granary at the terraced vines of Grapehollow. Today the books show a list of corridors, and the numbers must be worked out before sundown. 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 <= 3418; the input is a connected tree.

Example 1:

Input: 2464 748 755 790 1080 36 329 1479 1600 920 1648 156 788 500 1773 1609 2360 316 391 188 650 3 590 1316 1902 513 845 100 1527 663 2230 43 177 335 346 159 162 61 308 983 1207 395 1570 1081 1620 98 146 748 1027 254 985 538 2025 391 864 71 293 2216 2221 284 401 569 1030 201 1162 199 2241 1864 2178 390 838 424 1660 174 347 568 954 234 1006 7 1350 1584 1769 309 832 583 604 822 1134 66 1906 1599 2264 211 368 1065 1948 312 2238 466 730 441 598 675 886 928 932 92 109 275 464 251 330 367 1673 134 343 1658 2348 864 1763 450 1251 930 933 297 1158 405 585 510 716 282 1035 331 1082 113 534 412 878 1697 2407 314 528 278 2039 33 270 1434 2352 499 1940 438 1075 961 1143 87 169 918 1015 199 1269 339 583 315 1548 741 903 37 68 1111 1132 2 5 154 525 983 2435 124 135 184 1590 191 2103 683 2340 457 1036 549 957 …
Output: 29

Example 2:

Input: 1238 456 595 170 180 30 73 49 82 130 892 758 923 381 447 173 994 222 257 44 208 672 831 18 152 329 455 1055 1164 135 138 103 316 64 131 570 821 120 348 266 1223 59 769 1126 1208 776 1043 492 832 349 501 147 341 58 738 2 6 45 88 47 429 119 953 375 550 353 400 180 665 142 507 146 1087 861 905 16 423 755 1089 83 91 236 926 1 116 164 357 52 401 61 107 174 272 305 410 621 1078 75 474 403 537 301 1132 14 378 234 1016 236 451 722 1107 95 109 441 729 110 312 265 1024 49 743 362 386 495 605 456 902 341 762 122 297 583 1003 715 736 571 1232 43 1170 507 924 29 86 113 156 117 206 451 599 162 167 75 89 44 1158 253 283 744 786 222 409 958 999 701 895 251 454 899 1189 615 877 115 434 349 619 66 353 872 1031 665 916 14 569 498 928 190 289 768 1057 76 254 80 242 157 200 27 123 921 976 101 640 814 915 198 5…
Output: 27

Example 3:

Input: 753 494 567 210 629 261 297 135 324 507 517 97 179 12 83 329 554 5 521 577 640 43 173 135 206 352 657 53 71 20 116 96 495 236 317 398 502 20 28 174 186 26 47 8 20 2 157 151 404 146 153 177 292 407 609 80 184 68 519 34 56 249 648 125 316 6 460 357 623 45 752 41 100 101 527 251 553 1 74 71 77 362 372 653 701 308 368 184 231 175 273 164 682 51 442 330 556 131 274 55 480 13 194 53 520 270 543 8 12 14 363 156 293 171 351 64 81 56 441 283 304 406 496 530 616 259 734 16 291 221 318 73 490 343 617 58 75 271 683 480 703 423 435 185 662 427 637 464 563 180 418 375 498 618 751 106 707 115 211 71 72 258 679 421 603 38 494 87 656 148 177 426 669 266 454 22 27 231 493 86 204 40 434 391 743 241 330 242 419 17 382 125 140 168 249 456 457 277 359 22 377 14 391 172 183 141 210 297 447 396 533 362 401 421 67…
Output: 28

Constraints:

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

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