CT38243

The Separate Camps of the Teal tunnels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the shale slopes of Greystone close for winter, Vani must finish the tunnels ledger - one figure at a time. 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 <= 2243; 0 <= m <= 4486; 1 <= u,v <= n.

Example 1:

Input: 1293 79 760 1070 712 742 150 717 574 660 725 1237 67 891 826 1190 230 1189 741 1216 514 841 605 804 108 309 945 965 157 543 133 674 435 713 169 552 395 1252 374 914 293 972 171 414 841 1082 562 681 292 579 813 923 301 327 432 1112 410 544 84 374 448 1026 582 1133 506 1274 416 733 764 1200 623 1264 153 1176 493 880 941 1216 329 373 461 1127 609 1181 220 372 620 678 607 725 378 661 708 1031 629 1283 438 1224 180 369 651 1011 876 1180 1003 1181 884 1224 110 158 465 634 996 1227 905 1291 561 564 531 1001 502 1069 560 764 443 731 31 457 348 1126 80 261 852 1040 583 675 334 444 218 1193 674 1195 617 1264 1028 1207 141 153 347 556 305 369 376 519 242 368 205 1138 276 321
Output: 1214

Example 2:

Input: 1286 4359 494 760 488 1102 272 1013 268 369 43 899 101 1240 255 476 1063 1273 153 1202 714 931 772 1270 261 808 769 871 480 661 1020 1063 241 555 83 1040 449 469 128 1241 82 768 246 423 376 772 666 742 31 237 632 794 136 730 393 436 484 604 448 1185 5 793 819 866 197 816 613 1097 125 326 318 977 397 426 767 1119 376 380 189 1066 460 636 12 507 362 537 859 1102 8 623 78 795 14 865 367 787 231 292 218 623 89 1019 360 870 123 1147 93 452 469 1104 147 466 869 1258 97 1275 266 619 862 1203 166 996 555 1069 5 281 720 828 802 1286 34 377 347 658 496 1251 770 1227 679 1260 150 1032 291 1199 180 1062 60 806 98 1138 658 1079 618 923 347 553 1233 1250 100 1142 740 1049 842 871 135 546 509 952 415 1201 57 657 865 928 188 493 62 168 363 624 1087 1162 386 1205 470 1258 554 946 420 562 531 668 14 424 275…
Output: 3

Example 3:

Input: 1828 2236 681 881 797 1740 1467 1582 217 278 789 953 1201 1435 687 1480 136 473 216 1764 612 1747 754 1534 297 1821 1330 1522 445 1610 666 857 67 402 870 1741 420 542 192 751 124 637 1263 1373 267 553 771 1538 1092 1733 106 179 1166 1702 723 1310 175 1242 225 956 74 1136 908 1199 550 1171 489 1602 754 1667 104 1519 828 1117 449 1378 591 1585 711 1417 227 252 314 493 320 922 1325 1367 1571 1647 964 987 138 1118 40 1810 539 730 234 1590 589 779 165 1408 320 655 1324 1605 10 1534 355 1677 208 773 1135 1425 54 1184 256 1769 746 1223 1022 1500 1234 1487 1412 1773 538 832 241 834 206 1243 435 1687 45 1547 683 897 1423 1609 583 1787 893 1160 595 1425 598 988 835 1156 1219 1625 454 1759 680 1083 409 1472 1029 1375 326 586 215 784 182 838 816 1078 644 1263 759 843 193 842 98 1292 900 979 1268 1635 …
Output: 186

Constraints:

1 <= n <= 2243; 0 <= m <= 4486; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.