CT44335

Chavi's Smoky bridges

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the indigo vats of Bluehollow opens only for a perfect tally of bridges. Chavi 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 <= 2476; the input is a connected tree.

Example 1:

Input: 1935 1173 1333 1090 1775 1540 1827 101 1483 1124 1189 265 279 79 1876 179 240 8 499 54 199 160 475 56 66 792 899 231 429 476 1642 108 427 308 341 140 178 198 354 191 450 909 1578 3 6 950 1692 1512 1689 111 249 928 1826 1487 1855 383 1033 725 981 1 381 108 664 382 745 5 40 65 214 608 803 22 131 522 1730 796 1528 242 275 504 1449 1061 1573 467 806 36 993 526 1830 1749 1890 37 45 433 497 1 2 351 1559 66 1925 66 535 69 452 222 541 130 139 1653 1668 837 895 1404 1608 40 460 15 107 258 483 983 1104 18 49 5 1728 1426 1459 135 784 343 1444 104 307 251 946 48 597 314 599 1639 1773 954 1819 1208 1469 1627 1814 77 220 124 935 22 927 208 1451 2 4 1393 1406 1058 1439 120 492 1062 1680 700 1753 1355 1484 129 516 429 1880 16 412 149 667 960 1428 289 1044 1 74 1273 1415 777 1091 255 1589 614 814 1558 1838…
Output: 31

Example 2:

Input: 758 93 301 16 342 66 213 43 587 221 542 56 208 591 660 77 98 156 310 357 578 1 21 290 295 216 457 283 484 132 709 20 46 140 348 573 630 21 535 17 74 170 177 76 91 5 36 160 366 284 377 350 618 12 26 119 137 101 245 65 71 388 505 8 65 94 562 23 329 321 526 73 152 78 656 20 513 201 338 66 124 26 277 270 690 8 16 160 226 445 739 82 249 146 385 126 523 580 728 265 491 155 572 498 695 314 394 345 649 434 549 360 525 45 282 59 99 119 408 215 275 128 413 50 141 211 405 12 197 26 37 526 544 62 437 115 534 513 625 129 165 512 614 21 53 620 623 15 51 79 411 247 268 64 126 398 592 339 626 417 481 165 252 93 258 86 640 186 218 57 602 477 591 346 380 165 198 288 539 74 365 29 211 72 103 28 678 327 360 89 298 216 689 147 305 39 80 99 256 299 615 144 146 168 194 102 121 7 11 164 182 490 676 420 468 535 72…
Output: 25

Example 3:

Input: 2108 90 1362 715 1828 143 658 733 1113 193 1140 633 1346 913 960 85 1969 270 1633 1758 1946 440 1249 48 2091 60 1059 267 607 503 2055 82 194 189 823 39 1709 332 1398 99 262 689 1133 88 759 1 40 339 1448 77 211 329 660 1263 1945 757 1575 100 122 441 1014 252 515 88 250 268 1843 452 1986 37 88 687 1075 171 524 321 836 240 525 816 847 1021 2004 158 282 47 111 167 270 202 1452 466 1011 146 408 159 386 2055 2107 152 154 29 335 1707 1747 92 939 409 1947 257 330 233 890 1089 1302 201 1070 229 842 94 959 1276 1582 1198 1763 853 1832 728 763 74 1128 134 342 233 1540 691 776 813 875 450 1273 175 1254 91 747 901 1285 565 1180 809 968 525 631 985 1844 1280 1281 413 455 40 71 15 46 473 1546 665 1010 51 273 31 294 67 1492 121 648 520 918 602 970 138 166 611 1067 1029 1030 363 1548 94 1345 445 565 315 40…
Output: 26

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Chavi's Smoky bridges - MEDIUM Coding Problem | CodeTikki