CT52039

Elsa and the Marble roads

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Elsa the factor watches over the honeycomb cliffs of Beeswick's stores of roads. A careful computation stands between order and chaos. Task: An undirected graph has n nodes and m edges. Print the number of connected components. Input format: First line: n and m. Next m lines: u v. Output format: Print the component count. Constraints: 1 <= n <= 3107; 0 <= m <= 6214; 1 <= u,v <= n.

Example 1:

Input: 2155 1989 308 1324 360 1782 731 964 216 1656 1188 1760 513 1142 1813 1977 1438 1892 45 187 1609 1624 13 323 580 1270 505 2078 1499 1533 203 1904 1517 1962 1145 1208 495 2136 1304 2074 79 1491 1085 2059 1166 1219 300 725 888 1776 380 981 1613 1617 1653 1753 632 1563 273 1435 509 719 1806 1930 863 2031 851 1670 1461 1803 447 587 478 2038 463 1623 1394 1409 387 1581 1205 1928 1436 2087 281 1617 724 1707 1470 1768 382 1097 1123 1471 586 728 500 1211 762 968 1407 1933 456 2090 206 639 1365 1991 439 1959 604 2020 1028 1872 217 1211 919 936 523 1601 146 1267 73 1276 844 1075 1057 1266 128 2090 271 1492 1383 2065 1175 1459 1071 1826 891 1751 795 1262 315 784 1314 1584 590 1152 489 817 682 1343 736 1644 1375 1605 1128 1630 50 544 244 795 68 1752 1051 2152 963 1963 1250 1632 60 1897 416 1761 219 129…
Output: 402

Example 2:

Input: 665 4592 330 485 508 553 27 86 149 227 154 334 222 535 25 194 450 459 265 657 182 482 129 164 35 55 463 534 129 382 122 306 48 390 71 454 129 519 49 271 211 395 144 611 322 529 80 588 110 286 2 557 251 374 43 270 593 634 284 573 72 365 505 640 347 579 86 366 203 508 120 432 230 391 9 145 350 428 213 252 55 90 599 636 55 498 478 628 351 569 92 603 50 635 187 405 43 352 252 302 126 607 331 479 331 388 259 266 130 415 51 596 299 458 265 501 344 440 393 481 329 514 225 319 108 329 136 475 419 607 405 433 55 148 424 545 454 593 258 276 430 642 87 428 250 480 147 426 57 618 62 595 121 474 376 471 280 562 179 314 311 391 410 527 65 420 75 603 186 257 7 179 70 558 410 538 85 575 115 224 65 286 199 381 316 346 196 659 327 538 534 597 127 290 381 621 162 359 323 648 393 505 143 421 558 641 184 228 5…
Output: 1

Example 3:

Input: 2539 2015 1524 2012 1210 1694 975 1436 516 577 729 1510 1790 2127 612 2228 231 1633 776 2305 135 2222 447 762 1594 1916 1060 2095 448 1562 1681 1759 160 447 286 796 499 2040 282 1040 121 776 1816 2037 858 869 109 1321 574 1417 291 921 799 1067 81 1200 20 829 1157 1652 1042 1698 598 1058 576 1813 125 2173 778 1564 343 1244 1063 1543 1062 1171 204 391 590 1785 783 1134 467 2221 529 1868 14 1370 875 2083 112 665 271 594 517 1503 1430 2286 394 1689 2131 2378 172 682 1541 1866 356 1621 1406 2150 1990 2172 1056 1364 410 833 168 1014 554 2539 413 2186 1330 2133 115 1895 1346 1639 311 957 269 1046 929 1230 301 625 54 475 2034 2393 281 1276 22 206 588 1637 1137 2041 975 1052 653 1418 1025 1625 182 476 85 2048 1263 1445 1156 1449 725 1014 1878 2460 406 802 769 2224 2351 2393 1024 2369 732 801 1396 2…
Output: 640

Constraints:

1 <= n <= 3107; 0 <= m <= 6214; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Elsa and the Marble roads - MEDIUM Coding Problem | CodeTikki