CT49442

Ojas Counts the routes

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the obsidian flows of Blackglass, someone must plan the festival budget. This year the task falls to Ojas, armed only with the routes register. 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 <= 2550; the input is a connected tree.

Example 1:

Input: 658 181 227 127 336 434 501 74 402 105 310 448 651 473 570 270 579 69 186 102 122 331 375 269 405 68 140 267 641 238 358 14 163 25 202 184 316 23 141 209 451 110 511 136 379 155 254 246 403 36 518 24 385 70 158 95 111 420 653 166 621 107 428 26 359 185 234 147 191 4 51 75 113 222 400 66 464 24 48 122 527 248 517 8 91 66 132 554 643 307 607 137 194 97 101 15 18 4 513 275 563 26 83 240 435 57 514 56 167 48 306 83 293 30 43 6 14 328 654 119 331 28 30 541 620 33 320 155 223 376 541 3 632 243 337 48 50 194 604 170 333 31 72 394 554 136 399 605 622 93 212 148 391 198 255 29 185 327 455 246 603 508 522 551 644 22 75 157 488 160 569 73 135 232 265 287 378 28 341 486 535 55 655 90 106 112 151 20 438 7 13 54 110 21 70 57 62 247 581 97 440 368 472 328 552 59 551 93 250 7 12 66 82 66 568 83 533 4 64 2…
Output: 25

Example 2:

Input: 1556 16 60 192 254 77 883 70 145 1065 1082 218 1024 365 741 1483 1533 621 1159 8 39 160 289 562 799 32 562 411 506 642 925 125 498 252 967 393 614 103 589 1172 1482 303 664 1062 1191 177 919 350 593 229 1318 747 1125 193 1121 101 282 787 865 371 1526 419 1552 637 1308 80 231 72 627 12 1334 194 1199 68 87 1486 1535 360 377 147 220 448 643 627 1378 475 786 357 652 342 439 164 635 812 1393 824 1448 1055 1399 361 830 211 433 462 507 681 1459 387 1166 1285 1458 465 1246 803 842 847 1542 489 1323 913 1402 363 370 176 1490 95 109 383 447 136 221 693 947 178 577 907 1023 242 548 446 763 221 1176 176 260 277 534 125 634 178 897 53 337 745 846 74 302 190 303 579 1254 504 1267 53 348 416 866 778 1068 92 647 599 994 141 177 165 209 488 509 260 693 348 1075 242 384 186 445 260 701 50 77 510 1206 381 12…
Output: 28

Example 3:

Input: 2378 256 2237 1625 2244 1965 2022 646 709 1314 2148 148 1196 1240 1723 283 703 644 1146 411 1137 2199 2247 1607 1993 148 1176 789 825 454 2284 210 227 492 1407 1534 1810 271 2080 472 1569 60 1041 806 894 371 576 904 1936 379 821 1400 2205 1788 2354 1031 1443 323 1282 671 1634 118 265 88 1290 426 521 1709 2277 1039 1555 176 1100 699 1374 1531 1780 368 433 585 1236 979 1240 113 1652 188 1852 402 407 1290 1341 14 27 254 301 188 219 561 1025 121 285 658 673 1646 2289 376 1400 40 314 1872 2270 569 713 259 1152 384 2192 30 200 292 326 718 2057 57 212 965 1516 438 1678 6 482 400 2032 1972 2171 1419 2199 674 814 56 580 888 1017 1582 1599 1770 2344 627 2089 91 1672 74 159 726 1987 621 1881 538 1546 742 863 1530 1590 609 1111 237 1620 1814 1892 1643 2198 112 739 805 902 1839 2068 897 2127 1293 1323 …
Output: 32

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Ojas Counts the routes - MEDIUM Coding Problem | CodeTikki