1320. Graph Decomposition

时间:2021-12-12 12:55:03

1320

简单并查集

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
using namespace std;
int fa[],r[];
int find(int x)
{
if(fa[x]!=x)
fa[x] = find(fa[x]);
return fa[x];
}
int main()
{
int i,u,v;
int flag = ;
for(i = ; i <= ; i++)
{
fa[i] = i;
r[i] = ;
}
while(cin>>u>>v)
{
int x = find(u),y = find(v);
if(x!=y)
{
fa[x] = y;
r[y]+=r[x]+;
}
else
r[y]+=;
}
for(i = ; i <= ; i++)
{
int x = find(i);
if(r[i]==)
continue;
if(x==i)
{
if(r[i]%!=)
{
flag = ;
break;
}
}
}
if(!flag)
printf("1\n");
else
printf("0\n");
return ;
}