CT37032

Leon's Jade tunnels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Leon the assayer watches over the orchard lands of Applerun's stores of tunnels. 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 <= 2321; 0 <= m <= 4642; 1 <= u,v <= n.

Example 1:

Input: 2094 2163 147 257 272 2038 230 1836 1383 1449 579 682 204 791 1716 1729 1798 1902 836 1245 532 1694 1006 1534 800 1756 129 1759 492 1763 120 176 773 1299 430 1503 92 96 523 1284 687 1972 1659 2012 1007 1872 614 807 1033 1735 393 1677 260 282 1537 1677 1149 1641 150 974 771 1267 1791 1827 1320 1974 1134 1226 900 1488 384 1334 1444 1873 90 835 1290 1307 1856 2050 1470 1849 614 810 1020 1498 1118 1690 498 1247 1240 1374 524 1841 1238 1331 1391 1982 100 2008 338 489 712 1332 143 911 859 1477 336 1998 370 1813 248 1144 1415 1443 37 1199 550 855 2048 2057 880 1419 432 464 179 1839 305 956 1380 2088 75 753 770 1854 116 1838 486 883 174 1486 830 1580 213 1151 241 1862 359 506 1243 1716 347 1229 953 1532 552 1957 64 986 375 510 279 1321 293 2029 314 894 312 1238 1510 1921 327 609 1601 1840 1164 168…
Output: 317

Example 2:

Input: 103 3272 12 69 21 46 2 96 39 45 51 75 26 87 22 78 59 84 5 83 22 30 31 40 99 102 20 34 24 26 16 30 2 6 69 95 66 99 66 72 37 76 38 70 8 18 29 99 1 63 12 80 73 96 11 36 15 94 10 56 57 99 22 47 20 89 27 84 89 101 69 89 20 71 89 97 12 94 59 77 22 31 24 43 59 62 59 98 21 44 79 93 72 83 44 66 11 50 46 97 71 102 90 95 27 68 39 101 4 49 16 25 20 39 100 103 10 38 63 84 45 62 46 99 51 69 65 78 52 102 6 100 27 75 41 75 46 93 5 53 84 91 22 24 53 95 32 67 25 102 15 25 44 45 39 44 43 100 60 69 53 72 9 45 82 99 1 69 88 95 72 91 74 85 26 64 84 88 22 61 73 92 31 37 36 53 36 49 27 48 64 92 10 63 14 54 6 62 85 100 38 96 20 59 40 96 12 31 17 22 44 47 4 93 37 68 34 36 6 36 5 54 29 73 47 51 29 92 15 71 54 76 34 48 76 101 26 50 17 93 47 84 63 79 38 81 42 48 37 88 31 94 29 80 35 97 51 91 9 30 18 30 42 71 57 85 8 7…
Output: 1

Example 3:

Input: 1916 4272 539 1340 442 1263 1116 1171 944 1433 709 1001 1330 1610 411 677 916 1402 488 1866 361 684 1072 1640 752 1847 570 947 1009 1780 1029 1601 710 1657 30 1839 1262 1640 1425 1738 466 639 597 1694 262 1863 1370 1721 930 1160 1017 1364 1288 1312 4 435 866 1618 1454 1519 1092 1892 23 1887 681 1579 752 1856 500 1734 207 1391 1552 1739 1008 1706 969 1691 1554 1558 514 1537 847 945 1562 1717 1381 1599 134 879 17 408 190 1051 433 1590 765 1286 1327 1646 157 210 494 752 801 1540 193 1021 243 936 43 1533 1227 1756 390 1585 152 1307 1486 1867 1596 1842 157 1449 437 1604 1419 1594 236 914 415 1896 169 704 883 1055 1155 1358 67 861 87 1360 517 1104 1424 1448 1368 1517 186 1014 185 274 412 1522 412 1148 340 885 99 1023 464 1034 69 432 542 940 788 1776 593 1530 713 1149 811 1022 367 598 239 1271 15…
Output: 20

Constraints:

1 <= n <= 2321; 0 <= m <= 4642; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Leon's Jade tunnels - MEDIUM Coding Problem | CodeTikki