poj 1703
来源:互联网 发布:统计学df知乎 编辑:程序博客网 时间:2024/04/29 22:54
#include<stdio.h>
#include<string.h>
#define N 100010
int father[N],link[N];
int find(int x) {
if(x!=father[x]) {
int h=father[x];
father[x]=find(father[x]);
link[x]=(link[x]+link[h])%2;
}
return father[x];
}
void insert(int x,int y) {
int xx=find(x);
int yy=find(y);
father[xx]=yy;
link[xx]=(link[x]+link[y]+1)%2;
}
int main() {
int t,n,m,a,b,i,f1,f2;
char s[3];
scanf("%d",&t);
while(t--) {
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
father[i]=i;
memset(link,0,sizeof(link));
while(m--) {
scanf("%s%d%d",s,&a,&b);
f1=find(a);
f2=find(b);
if(f1==f2) {
if(s[0]=='A') {
if(link[a]==link[b])
printf("In the same gang.\n");
else
printf("In different gangs.\n");
}
}
else {
if(s[0]=='A')
printf("Not sure yet.\n");
else
insert(a,b);
}
}
}
return 0;
}
- poj 2492 && poj 1703
- poj 1703
- POJ 1703
- poj 1703
- POJ 1703
- poj 1703
- poj 1703
- POJ 1703
- POJ 1703
- poj-1703
- poj-1703
- poj 1703
- POJ 1703
- poj 1703
- POJ 1703
- poj 1703
- POJ 1703
- poj 1703
- 提高HBase写性能
- hdu-1002-Java大数加法
- 使用Flash as3实现音频波形与条形EQ显示的方法
- 【Android设备管理】 利用DevicePolicyManager执行屏幕锁定
- HBase运维经验
- poj 1703
- go语言示例(总目录)
- 大数据应用之个性化推荐的十大挑战
- HBase缓存的使用
- 参加OpenMap的感受
- 电话拨号器
- 浮点数比较大小
- 嘀嗒APP打车体验记
- PKU1574&&DFS