CT34994

Dorian and the Separate Camps

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

In the basalt cliffs of Obsidian Shore, Dorian the cartographer keeps careful count of the canals. Reorganize the archive shelves, every figure matters. 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 <= 1970; 0 <= m <= 3940; 1 <= u,v <= n.

Example 1:

Input: 1811 1011 172 1734 386 778 228 1090 654 817 1302 1753 1562 1773 360 396 314 537 664 691 1070 1180 612 738 758 1278 565 868 344 1189 1601 1794 910 979 848 1017 1205 1557 1259 1482 335 838 1612 1788 376 557 1035 1312 410 460 535 781 112 540 321 1066 450 1121 526 1570 429 1091 96 1377 155 350 270 1146 937 1592 482 1736 585 961 13 1009 373 733 544 1520 641 1403 105 748 1467 1512 148 431 394 450 847 1734 966 1614 936 1484 580 973 771 971 666 1683 92 705 396 850 908 1539 267 1268 25 92 171 1731 220 1101 413 570 2 203 1714 1767 148 1198 22 943 797 1789 617 1201 383 953 8 880 126 1595 990 1413 229 1501 1057 1356 566 813 151 1055 1276 1631 714 1766 664 1139 1108 1274 330 714 490 567 690 1378 1337 1413 1091 1327 508 555 294 505 679 802 886 1643 756 1754 234 1071 19 308 338 1781 295 539 72 209 1034 1…
Output: 806

Example 2:

Input: 1536 2334 225 243 181 1451 697 1387 143 475 373 806 660 887 100 1226 668 885 150 676 982 1268 92 251 1241 1472 83 482 654 798 1338 1422 458 597 89 730 581 774 254 1134 16 754 92 1024 720 1141 260 613 1022 1077 545 781 1227 1319 1009 1164 818 1255 638 787 728 1341 749 1460 383 801 412 605 275 651 1243 1329 27 248 285 481 737 846 103 493 291 1412 210 1278 790 993 694 839 751 805 965 1149 1187 1310 316 922 285 550 1297 1483 192 1057 174 1153 875 992 755 1125 765 1144 437 965 942 958 891 1252 704 1406 111 831 122 496 171 1316 350 719 470 1434 3 212 881 1180 379 1101 661 1149 165 1105 1252 1374 298 1214 465 1476 411 645 991 1041 582 1076 191 336 258 1187 512 1007 271 1380 28 269 34 1304 836 1385 192 1269 870 1360 600 1303 771 1245 506 1200 464 1369 1063 1464 76 1207 436 1357 1081 1261 610 755 1…
Output: 89

Example 3:

Input: 312 901 25 279 45 62 12 284 103 212 115 265 212 312 37 108 267 270 253 310 80 89 107 245 38 230 69 139 17 23 152 169 13 151 204 276 138 312 121 302 50 239 231 261 150 264 7 286 4 26 131 232 132 212 149 245 40 284 74 264 193 274 45 47 148 239 257 308 96 206 84 139 232 273 70 311 97 277 43 207 98 162 32 206 89 203 71 88 131 309 100 257 133 223 152 177 20 99 63 186 178 294 184 305 115 125 131 267 13 261 71 186 15 260 171 185 256 288 68 255 27 30 91 158 214 275 114 179 105 183 52 73 26 280 94 238 28 145 110 123 175 304 188 308 175 199 152 218 27 137 45 107 52 271 153 257 109 203 89 298 168 272 18 109 15 185 63 152 183 266 71 79 150 207 45 222 17 48 95 105 17 132 142 303 19 170 69 222 114 165 73 190 46 308 20 170 95 135 31 114 69 115 291 304 4 64 104 185 65 203 56 131 7 110 23 119 65 281 62 133…
Output: 4

Constraints:

1 <= n <= 1970; 0 <= m <= 3940; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Dorian and the Separate Camps - MEDIUM Coding Problem | CodeTikki