Description
Input
Output
Sample Input
3 3 1 2 1 3 2 3 3 2 1 2 2 3 0
Sample Output
1 0
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w",stdout);
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long LL;
const int MAXN=1000+5;
int DU[MAXN];
int n,m,sz;
int father[MAXN];
void edge_init(){
memset(DU,0,sizeof(DU));
for(int i=1;i<=n;i++){
father[i]=i;
}
}
int Find(int x){
if(x!=father[x]){
father[x]=Find(father[x]);
}
return father[x];
}
int main()
{
//FIN
while(~scanf("%d",&n),n)
{
scanf("%d",&m);
edge_init();
int sum=n;
for(int i=1;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
DU[u]++;
DU[v]++;
int root1=Find(u);
int root2=Find(v);
if(root1!=root2){
father[root2]=root1;
sum--;
}
}
if(sum!=1){
printf("0\n");
continue;
}
bool flag=1;
for(int i=1;i<=n;i++){
if(DU[i]%2==1){
flag=0;
printf("0\n");
break;
}
}
if(flag) printf("1\n");
}
return 0;
}
原文:http://www.cnblogs.com/Hyouka/p/5743173.html