直接解释输入了:

第一行cases.

然后是n和m代表有n个人,m个操作

给你两个空的集合

每个操作后面跟着俩数

D操作是说这俩数不在一个集合里。

A操作问这俩数什么关系

不能确定:输出Not sure yet.

在一个集合里:输出In the same gang.

不在一个集合里:输出In different gangs.

这题挺像http://poj.org/problem?id=2492同性恋的虫子那道题的。

// by SiriusRen
#include <cstdio>
#include <cstring>
using namespace std;
int cases,xx,yy,n,m,f[105000],d[100500];
char jy,jy1;
int find(int x){
if(f[x]==x)return x;
int y=f[x];
f[x]=find(f[x]);
d[x]=(d[x]+d[y])%2;
return f[x];
}
int main(){
scanf("%d",&cases);
while(cases--){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)f[i]=i;
memset(d,0,sizeof(d));
for(int i=1;i<=m;i++){
scanf("%c%c%d%d",&jy1,&jy,&xx,&yy);
int fx=find(xx),fy=find(yy);
if(jy=='A'){
if(fx!=fy)puts("Not sure yet.");
else if(d[xx]!=d[yy])puts("In different gangs.");
else puts("In the same gang.");
}
else f[fx]=fy,d[fx]=(d[yy]-d[xx]+1)%2;
}
}
}

POJ 1703 带权并查集的更多相关文章

  1. poj 1182 (带权并查集)

    食物链 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 71361   Accepted: 21131 Description ...

  2. poj 1733(带权并查集+离散化)

    题目链接:http://poj.org/problem?id=1733 思路:这题一看就想到要用并查集做了,不过一看数据这么大,感觉有点棘手,其实,我们仔细一想可以发现,我们需要记录的是出现过的节点到 ...

  3. Navigation Nightmare POJ - 1984 带权并查集

    #include<iostream> #include<cmath> #include<algorithm> using namespace std; ; // 东 ...

  4. Parity game POJ - 1733 带权并查集

    #include<iostream> #include<algorithm> #include<cstdio> using namespace std; <& ...

  5. K - Find them, Catch them POJ - 1703 (带权并查集)

    题目链接: K - Find them, Catch them POJ - 1703 题目大意:警方决定捣毁两大犯罪团伙:龙帮和蛇帮,显然一个帮派至少有一人.该城有N个罪犯,编号从1至N(N<= ...

  6. POJ 1703 Find them, Catch them(带权并查集)

    传送门 Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42463   Accep ...

  7. (中等) POJ 1703 Find them, Catch them,带权并查集。

    Description The police office in Tadu City decides to say ends to the chaos, as launch actions to ro ...

  8. poj 1703 - Find them, Catch them【带权并查集】

    <题目链接> 题目大意: 已知所有元素要么属于第一个集合,要么属于第二个集合,给出两种操作.第一种是D a b,表示a,b两个元素不在一个集合里面.第二种操作是A a b,表示询问a,b两 ...

  9. POJ 1703 Find them, Catch them【种类/带权并查集+判断两元素是否在同一集合/不同集合/无法确定+类似食物链】

      The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the ...

随机推荐

  1. Glitch-free clock switch

    With multi-frequency clocks being used in today’s devices, it's necessary to switch the source of a ...

  2. 个人作业—Alpha测试

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1/homework/3338 这个作业要求在哪里 htt ...

  3. We wanted {"required":["value"]} and you sent ["text","value","id","sessionId"]

    重装python pycharm后再次执行以前执行没有问题的Appium脚本报错 We wanted {"required":["value"]} and yo ...

  4. 单链表每k个节点为一组进行反转(最后不满k个时不反转)

    public class LinkReverse2 { public static Node mhead=null; public static Node mtail=null; public sta ...

  5. vue-属性传值 props

    props属性传值 1.传具体的值  string(字符串) number(数值) boolean(布尔) 2.传一个引用 array(数组)  object(对象) ----传引用----- 代码 ...

  6. Selenium3+python自动化-iframe

    一.frame和iframe区别 Frame与Iframe两者可以实现的功能基本相同,不过Iframe比Frame具有更多的灵活性. frame是整个页面的框架,iframe是内嵌的网页元素,也可以说 ...

  7. Vue + Element 小技巧

    说是小技巧 ,其实就是本人 就是一个小菜比 .如有大佬可以纠正,或者再救救我这个小菜比    跪谢 1.当后台返回一个字段需要根据不同字段内容在表格内显示相对应的文字(字段内容是死的,表格内需要显示对 ...

  8. 【微软2017年预科生计划在线编程笔试第二场 A】Queen Attack

    [题目链接]:http://hihocoder.com/problemset/problem/1497 [题意] 给你n个皇后; 然后问你其中能够互相攻击到的皇后的对数; 皇后的攻击可以穿透; [题解 ...

  9. iOS不同版本号适配问题(#ifdef __IPHONE_7_0)

    部分參考http://www.cnblogs.com/ios8/p/ios-version-com.html 以下举个简单的样例来说明在iOS7.0和iOS6.1(以及更低版本号)之间的适配问题(用的 ...

  10. Mybatis结合Spring注解自己主动扫描源代码分析

    作为一个想做架构师的程序猿,必须是一个优秀的程序猿.在引入某一个框架的时候,必需要研究源代码,将新的开源框架的风险变为可控性. 1.Spring结合Mybatis最经常使用的配置. <!--理论 ...