CT50379

Iker's Granite bridges

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Morning light hits the granite steps of Stonehallow as Iker unrolls the day's manifest of bridges. The tally will decide the next shipment. 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 <= 3185; 0 <= m <= 6370; 1 <= u,v <= n.

Example 1:

Input: 2377 3868 14 1037 1472 2340 396 1781 1216 2241 300 1300 301 1573 573 1478 90 235 1248 1346 901 1554 248 2343 719 2348 828 831 84 2271 18 2214 2045 2344 1462 1838 1118 1958 369 2305 275 652 242 1507 311 1287 1334 1654 812 1560 1019 1407 276 1201 2117 2124 1518 2366 880 1080 1480 1654 826 1663 128 2094 1285 1928 2 1165 1081 1505 1193 2232 423 2198 870 2240 1861 1918 422 1885 105 1198 1071 1418 1467 1717 203 2107 1777 2060 327 924 845 1791 19 1243 973 1804 1681 1695 505 2032 1416 1961 544 2018 732 1026 483 2089 1873 2203 1084 1100 440 2316 70 1942 301 853 804 1164 215 437 1260 1386 1641 1969 578 1153 698 2161 179 564 1124 1308 216 1838 38 2346 930 2026 957 1571 683 766 824 1590 630 713 582 2232 890 2103 1158 1160 523 694 798 1208 593 1470 643 705 428 1520 861 1140 2158 2206 19 1326 1125 1368 …
Output: 98

Example 2:

Input: 498 6177 276 283 176 245 126 169 83 481 187 243 316 440 130 191 155 321 255 301 207 354 33 63 167 355 274 375 49 382 7 481 209 239 86 311 174 189 473 479 319 473 32 134 340 424 36 50 178 398 62 193 136 219 39 242 221 437 233 396 160 389 170 181 209 442 102 454 38 97 209 378 166 463 246 463 111 159 143 371 244 286 13 101 4 416 340 432 59 92 125 415 244 485 102 386 140 174 30 392 24 39 54 332 21 32 276 410 228 463 25 463 319 435 398 463 267 440 236 473 135 156 176 438 60 197 435 477 15 407 387 403 171 213 13 207 228 279 158 418 43 479 6 407 35 338 53 74 162 276 78 475 344 445 308 355 457 458 71 281 81 452 405 481 213 313 384 468 68 368 57 343 19 109 12 441 285 307 189 463 69 466 79 334 28 347 312 332 58 367 24 174 72 271 339 484 291 375 163 484 50 459 232 266 83 246 22 490 106 331 112 329 91…
Output: 1

Example 3:

Input: 2474 4593 415 1193 392 689 1172 1757 48 1646 824 1760 1252 1302 273 2440 506 1204 1053 1957 1055 1519 2075 2396 1753 2065 175 346 20 2322 612 757 882 1481 92 1967 936 2102 1786 1869 765 1648 1445 2349 1489 2198 578 2347 546 2083 1776 2243 1153 1706 650 1307 111 898 204 1197 550 775 452 1410 639 1726 840 2369 1450 2011 2325 2466 879 2417 1040 1570 1278 1511 823 937 274 2004 1837 2386 118 2376 215 2229 1315 2367 483 913 690 1048 904 1213 1155 1383 163 2423 178 223 237 1635 53 2463 919 2365 867 1731 88 127 755 2067 421 462 709 1549 392 1731 727 2462 1065 1694 340 972 362 1407 1739 2356 240 806 246 1066 1802 1891 911 1718 1087 1911 1759 2282 1195 2030 474 1046 1535 1832 489 1148 466 1075 1090 1161 744 1023 56 1908 277 1435 2176 2213 940 946 5 723 404 693 1320 1399 93 2022 1236 1878 1139 2463 1…
Output: 59

Constraints:

1 <= n <= 3185; 0 <= m <= 6370; 1 <= u,v <= n.

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