CT52780

Mira and the Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the shale slopes of Greystone, someone must verify the safety inspections. This year the task falls to Mira, armed only with the canals register. 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 <= 1478; 0 <= m <= 2956; 1 <= u,v <= n.

Example 1:

Input: 1370 1210 314 1272 129 334 324 737 68 992 149 750 922 970 747 784 763 781 417 592 624 1288 1118 1190 55 245 922 1314 1081 1321 68 119 656 714 839 857 311 1024 361 379 213 217 932 1283 515 1331 419 1345 853 1283 909 1251 598 799 1044 1103 418 611 592 885 5 786 133 796 980 1092 980 1138 969 1221 1117 1340 497 1019 658 733 209 1216 746 1000 547 801 373 975 105 933 180 543 145 864 857 926 702 1344 624 725 116 929 207 1148 54 1034 475 721 38 783 431 1136 423 804 1223 1298 368 1030 1012 1292 857 1239 163 951 958 1174 145 901 298 777 1005 1034 233 1303 296 581 414 1146 167 250 64 407 505 517 1003 1321 161 854 292 1203 704 901 335 704 682 715 537 1167 580 1224 601 1184 1071 1196 36 707 832 1293 734 997 676 824 599 1004 602 739 800 1237 295 897 185 712 487 888 48 814 221 351 567 622 100 929 84 1118…
Output: 290

Example 2:

Input: 1008 1054 524 782 381 387 10 13 87 862 147 173 343 819 109 289 71 720 814 979 898 964 77 923 108 234 481 680 62 100 85 932 554 879 235 266 260 749 275 909 355 406 66 672 689 920 642 761 845 1005 386 736 110 907 471 794 176 641 551 852 85 496 7 107 288 663 508 740 280 953 136 837 254 908 275 832 198 508 207 680 91 285 418 479 808 910 397 500 315 801 85 410 660 800 701 812 121 654 65 505 648 662 781 995 142 285 306 597 589 637 104 106 34 595 912 920 747 891 574 799 734 841 199 588 136 296 548 813 118 882 226 650 289 846 123 705 43 920 565 918 144 286 30 977 517 848 399 812 614 739 138 821 274 635 453 557 270 350 673 1006 292 629 307 761 489 749 739 816 831 863 574 816 7 909 47 614 219 659 97 338 120 198 259 535 738 889 306 977 393 436 347 654 232 671 460 749 300 549 515 792 300 810 314 446 1…
Output: 151

Example 3:

Input: 1294 352 546 1222 479 1132 220 586 460 840 245 688 664 706 89 508 424 941 683 1094 433 444 373 693 110 161 152 366 562 628 118 279 65 119 324 1071 696 907 664 1100 277 410 315 1191 35 1128 360 668 1056 1272 439 590 113 374 630 662 299 1291 228 1094 344 536 829 959 672 1024 294 929 131 739 348 1115 285 1079 557 844 856 910 94 1277 103 121 288 404 1131 1273 179 1212 119 659 1100 1226 499 1215 825 1292 428 791 339 1045 543 769 960 1149 5 627 622 1086 537 1147 1127 1165 829 1193 225 1283 682 1062 95 964 504 850 464 1064 133 955 769 895 703 1225 701 1271 340 894 385 591 106 996 392 966 1118 1147 274 451 646 855 574 798 2 728 95 160 234 1145 42 1021 544 585 301 634 450 1288 99 241 810 1011 412 769 407 905 113 1168 422 825 510 1095 825 1126 435 655 369 458 216 544 356 1091 97 125 550 1109 1116 12…
Output: 942

Constraints:

1 <= n <= 1478; 0 <= m <= 2956; 1 <= u,v <= n.

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