标签:void clu next red ios turn iostream string 它的
完全图,给出一部分,求补图连通分量个数
图G不连通,则它的补图必连通。
对于每一个点(没有被访问过),枚举不和它相连并且没有访问过的点,依次dfs下去,得到一个连通分量.
#include<iostream>
#include<string>
#include<string.h>
#include<vector>
#include<unordered_map>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
set<int> s[N];
map<int,int> mp[N];
bitset<N> b;
int n, m;
void dfs(int u) {
b[u] = 0;
for (int i = b._Find_first(); i < b.size(); i = b._Find_next(i)) {
if (!mp[u][i])
dfs(i);
}
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++)
{
int x, y;
scanf("%d%d", &x, &y);
mp[x][y] = mp[y][x] = 1;
}
for (int i = 1; i <= n; i++)
b[i] = 1;
int sum = 0;
for (int i = 1; i <= n; i++)
if (b[i])
{
dfs(i);
sum++;
}
printf("%d\n", sum-1);
return 0;
}
标签:void clu next red ios turn iostream string 它的
原文地址:https://www.cnblogs.com/fluxation/p/12236290.html