CT52564

Jace's Longest Trail Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Jace runs the print shop at the crane marshes of Stillwater. Today the books show a list of canals, 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 <= 3324; the input is a connected tree.

Example 1:

Input: 2328 755 2091 455 1139 1487 1790 440 550 1263 2243 1596 1694 66 424 60 100 50 98 627 1128 182 216 163 464 1008 1419 1078 1324 218 302 1027 2222 45 132 132 710 1426 2199 907 1937 44 657 70 1341 199 793 226 1109 7 16 127 316 220 766 259 984 386 1095 446 1311 20 1673 498 568 104 501 1316 1993 648 730 104 145 9 208 614 883 1146 1189 1170 2210 909 1253 345 870 770 1577 311 1160 102 240 833 1072 846 1984 1278 2120 66 75 811 1909 27 2251 226 976 217 1217 1551 1828 1037 1065 713 1059 1283 2150 837 2123 774 1445 1021 1730 515 713 362 1525 1569 2218 138 271 861 1478 414 2301 1501 2293 174 426 675 2323 34 116 269 686 96 110 680 1011 1827 2324 34 111 1774 2280 122 412 296 589 270 1516 321 1658 134 1882 1439 2296 1545 2023 361 1043 1118 1408 644 772 321 2297 921 1923 159 440 220 254 656 2169 984 1554 6…
Output: 26

Example 2:

Input: 710 204 523 345 400 131 194 142 278 178 440 181 603 23 24 89 143 7 459 35 240 140 348 78 687 10 122 1 12 97 333 219 546 136 418 22 103 55 65 414 666 542 574 6 145 23 374 336 431 10 220 22 108 86 187 21 70 219 595 1 45 247 323 23 696 225 476 508 522 327 621 1 246 131 244 296 671 32 119 26 59 121 159 217 624 272 433 190 419 335 642 101 341 50 116 111 632 50 359 87 643 495 518 4 408 76 153 113 141 23 327 418 493 115 152 279 710 106 336 167 667 121 410 100 207 82 693 181 290 123 427 21 125 20 37 102 263 209 330 138 201 268 678 255 698 46 86 16 110 276 385 362 399 381 508 9 15 1 17 5 352 32 53 24 565 300 432 23 33 72 686 97 268 28 342 38 230 20 171 21 67 528 592 287 560 283 473 161 297 307 467 182 273 8 77 174 274 24 295 150 178 31 107 186 252 31 197 98 115 560 609 71 250 140 288 562 600 168 38…
Output: 22

Example 3:

Input: 2341 1041 2082 1140 1985 337 1671 498 1887 509 2148 5 149 60 1854 339 485 598 625 1045 1962 424 2311 21 119 82 1552 45 117 1101 1514 91 1696 841 877 53 1713 881 955 1671 2237 104 1469 360 479 1610 2064 193 496 73 562 404 1355 508 2219 526 573 462 831 432 584 187 733 699 971 1089 1451 691 1104 11 18 1147 2168 370 596 1164 1246 1569 1658 214 2016 243 673 1882 1954 669 1172 74 221 611 1343 104 1904 876 1379 35 115 206 449 1224 1231 404 1709 830 2099 1575 1910 94 2100 29 2033 1585 2106 459 1192 128 215 232 455 169 286 577 1152 362 599 224 240 407 532 505 679 326 810 744 1025 38 216 684 1686 1322 1646 2006 2012 295 315 626 2133 80 592 418 721 658 851 922 1296 468 650 533 1137 5 917 730 754 236 551 722 1839 22 632 868 1150 1295 1488 616 953 451 1978 121 505 1509 2292 179 1050 632 1414 262 639 88…
Output: 25

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Jace's Longest Trail Ledger - MEDIUM Coding Problem | CodeTikki