题意 :给定一系列数对,例如a和b,表示a和b不是同一种性别,然后不断的给出这样的数对,问有没有性别不对的情况。
#include<cstdio>
using namespace std;
const int N=2100;
int f[N],r[N];
int seek(int x){
if(x==f[x]) return x;
int fa=f[x];
f[x]=seek(f[x]),r[x]=r[x]^r[fa];
return f[x];
}
int main(){
int T;scanf("%d",&T);
for(int cas=1;cas<=T;cas++){
int n,m;scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) f[i]=i,r[i]=0;
int flag=0;
while(m--){
int x,y;
scanf("%d%d",&x,&y);
if(flag) continue;
int rx=seek(x),ry=seek(y);
if(rx==ry&&!(r[x]^r[y])) flag=1;
else if(rx!=ry) f[rx]=ry,r[rx]=~(r[x]^r[y]);
}
printf("Scenario #%d:\n",cas);
puts(flag?"Suspicious bugs found!\n":"No suspicious bugs found!\n");
}
}
#include<bits/stdc++.h>
#define m(a,b) memset(a,b,sizeof a)
using namespace std;
typedef long long ll;
const int N=2100;
int f[N<<1];
int seek(int x){return (x==f[x])?(x):(f[x]=seek(f[x]));}
int main(){
int T;scanf("%d",&T);
for(int cas=1;cas<=T;cas++){
int n,m;scanf("%d%d",&n,&m);
for(int i=1;i<=n<<1;i++) f[i]=i;
int flag=0;
while(m--){
int x,y;scanf("%d%d",&x,&y);
if(flag) continue;
if(seek(x)==seek(y)){flag=1;continue;}
f[seek(x)]=seek(y+n),f[seek(x+n)]=seek(y);
}
printf("Scenario #%d:\n",cas);
(flag)?puts("Suspicious bugs found!"):puts("No suspicious bugs found!");
puts("");
}
}