CT38782

Rosa and the Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Rosa inherited the exchange at the rook towers of Chessfield along with its curious bookkeeping system for bridges. Time to make sense of it. 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 <= 2474; 0 <= m <= 4948; 1 <= u,v <= n.

Example 1:

Input: 1371 1307 1190 1258 373 381 552 920 171 363 1073 1313 243 689 138 772 57 1271 894 1126 531 608 184 1116 42 729 306 1220 168 587 352 664 317 651 514 1002 481 1354 14 80 384 479 207 737 235 468 873 899 553 1308 84 1240 350 1238 885 1153 300 1233 434 446 53 789 1128 1162 605 742 655 1028 618 1166 624 1042 106 267 449 1160 934 1079 57 508 339 353 956 1037 80 182 279 1355 280 898 221 463 131 824 95 1313 1175 1258 13 1245 745 1113 128 498 500 988 78 1261 220 1055 333 694 697 1220 1130 1311 825 1055 615 626 352 451 597 1247 247 503 60 1149 612 716 53 334 25 63 253 817 1092 1325 351 488 985 1354 188 1142 163 1357 626 1021 548 1240 78 701 273 804 292 629 995 1026 1038 1074 182 1101 967 1150 391 699 235 254 1105 1147 342 833 143 813 78 632 93 301 286 841 489 724 164 487 139 873 505 1040 752 785 395 …
Output: 257

Example 2:

Input: 1992 478 1707 1823 673 1782 988 1022 55 343 937 1273 393 993 490 1614 301 1819 780 1098 589 1130 1734 1784 1507 1627 1128 1727 809 1574 1207 1638 1430 1805 321 640 1144 1655 642 1369 435 955 237 1136 846 1389 511 1875 636 1724 1782 1927 1251 1542 337 422 28 526 1759 1806 948 1133 812 1754 1401 1678 372 584 398 1211 773 885 26 1361 1742 1823 492 618 96 1308 498 778 1036 1704 1254 1422 615 1760 375 1656 1086 1913 59 167 961 1345 262 1036 681 929 768 872 684 1276 163 1279 759 856 957 1135 320 1853 411 1365 218 221 588 1854 1359 1381 340 1901 200 574 474 973 53 1525 297 910 68 1686 120 408 504 1951 1292 1540 540 1668 399 1660 7 1349 829 1974 309 878 1414 1771 361 597 102 1226 1135 1584 1259 1642 409 1426 1320 1742 934 1095 70 482 510 650 2 1412 781 1392 1183 1778 151 831 1618 1659 225 1261 603…
Output: 1514

Example 3:

Input: 461 1917 79 140 30 356 46 382 136 404 175 276 125 370 416 423 23 234 13 61 17 163 96 105 246 451 43 432 57 237 260 384 16 224 84 456 151 195 237 380 164 283 273 366 114 323 46 167 193 255 188 282 215 234 78 252 10 250 112 384 206 297 60 203 45 212 269 430 92 425 135 328 380 459 173 243 435 453 170 252 45 332 424 457 113 344 74 157 365 456 173 307 306 388 272 391 340 449 154 160 186 374 6 390 91 445 79 366 14 275 324 327 56 386 41 204 237 392 8 72 135 311 222 279 31 147 256 453 212 374 9 135 284 322 29 232 172 369 100 333 173 412 7 277 67 384 286 302 159 424 248 429 106 313 138 220 197 426 28 165 51 376 210 369 145 423 4 353 28 270 22 269 35 282 42 58 222 302 152 211 284 290 29 387 186 373 51 424 246 262 275 328 12 417 341 342 72 265 31 446 440 450 98 173 219 422 276 396 159 438 209 443 166…
Output: 1

Constraints:

1 <= n <= 2474; 0 <= m <= 4948; 1 <= u,v <= n.

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