CT40845

Porter's routes Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the boar woods of Tuskmore pays by the answer, and Porter intends to earn it. First: the full register of routes. 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 <= 2075; the input is a connected tree.

Example 1:

Input: 788 30 118 378 496 533 539 30 65 279 688 691 734 29 210 98 592 138 726 45 165 365 697 188 396 301 535 75 135 211 292 150 523 120 140 216 348 172 225 291 417 194 213 100 299 21 48 357 621 317 400 63 778 335 363 72 255 93 661 248 337 208 758 112 397 380 717 54 98 466 704 540 542 317 415 81 191 20 423 42 158 5 113 48 88 62 175 571 611 404 672 120 446 331 696 271 349 451 666 129 149 117 156 222 240 295 359 230 568 39 182 136 564 14 89 49 223 89 771 35 66 99 346 372 686 149 668 95 286 117 160 383 587 29 787 35 708 49 76 290 664 340 414 22 44 103 174 16 462 70 73 61 614 354 360 48 549 327 524 550 629 39 327 10 429 128 444 207 253 25 31 187 501 6 12 192 452 104 106 124 239 280 356 17 325 41 123 67 623 112 394 27 573 104 494 21 738 213 272 292 329 619 649 246 402 106 369 288 646 67 79 264 314 191 …
Output: 22

Example 2:

Input: 1258 150 176 749 783 507 824 42 132 71 354 816 1106 9 11 16 1111 391 1070 137 430 530 803 1 7 247 504 40 83 134 658 6 1076 1066 1214 25 454 267 403 17 999 316 682 165 659 542 648 85 214 502 562 615 1101 61 412 1056 1246 68 405 160 534 231 1190 558 794 556 746 503 987 40 1223 169 271 46 352 804 1193 30 251 259 286 124 823 343 414 297 727 171 329 82 298 167 483 434 916 402 839 37 150 3 59 54 438 909 959 23 330 91 186 88 451 146 857 111 296 667 1136 683 1007 486 956 5 30 240 1169 23 57 464 510 874 1088 2 310 81 1093 601 715 231 1081 2 318 77 274 1050 1052 5 12 60 426 740 1152 7 703 68 87 565 666 604 652 509 542 230 457 16 54 609 1255 2 19 935 1191 449 1170 103 255 496 628 348 695 53 563 285 1186 24 1258 838 1253 127 551 67 268 84 152 33 337 216 380 786 1004 486 528 132 153 432 467 126 1053 65…
Output: 28

Example 3:

Input: 1348 295 385 341 494 939 1002 87 403 311 733 472 665 166 862 1130 1185 410 796 420 898 195 1057 790 1019 688 1128 197 933 54 1347 759 851 219 455 434 1342 15 669 278 1250 157 1044 31 294 439 730 287 1115 96 99 132 802 222 488 98 425 161 355 570 1268 1124 1132 63 1030 382 1345 61 360 2 30 17 58 20 228 493 809 55 59 111 231 172 250 624 914 190 302 162 627 683 1020 816 969 492 877 28 183 94 324 230 248 429 653 29 161 5 108 953 1346 467 1255 17 93 614 950 701 961 93 524 128 368 416 667 202 225 485 505 11 820 153 396 107 359 55 1277 470 475 60 518 28 37 240 407 46 212 207 246 109 237 11 1339 138 348 215 1181 89 213 134 140 57 501 15 126 244 1204 568 745 25 128 81 118 24 222 210 1049 269 918 879 1292 140 157 871 1095 20 65 70 845 25 52 113 127 21 77 588 1007 89 610 108 165 73 829 1055 1156 158 5…
Output: 32

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Porter's routes Reckoning - MEDIUM Coding Problem | CodeTikki