直接解释输入了:

第一行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. 安卓使用JNI-NDK

    详细配置,参考链接:http://www.jb51.net/softjc/115204.html 一  .为什么使用NDK 1.代码的保护.由于apk的java层代码很容易被反编译,而C/C++库反汇 ...

  2. <aop:aspectj-autoproxy />

    通过配置织入@Aspectj切面 虽然可以通过编程的方式织入切面,但是一般情况下,我们还是使用spring的配置自动完成创建代理织入切面的工作. 通过aop命名空间的<aop:aspectj-a ...

  3. Type inference

    Type inference refers to the automatic detection of the data type of an expression in a programming ...

  4. promise原理及使用方法

    Promise 的含义 所谓Promise ,简单说就是一个容器,里面保存着某个未来才回结束的事件(通常是一个异步操作)的结果.从语法上说,Promise是一个对象,从它可以获取异步操作的消息. re ...

  5. react和vue对比

    相同点 都支持服务器端渲染 都有Virtual DOM,组件化开发,通过props参数进行父子组件数据的传递,都实现webComponent规范 数据驱动视图 都有支持native的方案,React的 ...

  6. eas之style接口

    Obj可以是KDTable对象,也可以是IRow,IColumn,ICell对象锁定Obj.getStyleAttributes().setLocked(true);Obj.getStyleAttri ...

  7. [转载]ext4文件系统的delalloc选项造成单次写延迟增加的分析

    转载http://www.cnblogs.com/cobbliu/p/5603472.html 最近我们的服务进程遇到kill -15后处于Z的状态,变为了僵尸进程,经过/proc/{thread_i ...

  8. Ubuntu安装RTX2080显卡驱动

    安装RTX2080显卡驱动 近日新购了一台DELL服务器,用于TensorFlow,由于显卡是另加的,需要安装显卡驱动. 服务器配置 服务器型号:DELL PowerEdge R730 CPU:2*I ...

  9. 为类型定义取别名、环境变量、静态库与动态库(day03)

    一.为类型命名别名 struct node{ int num; struct node *next; }; typedef struct node node_t; node_t n; 使用typede ...

  10. 23.partial update

    主要知识点 1.什么是partial update(部分修改) 2.partial update的语法 3.在es内部partial update的实现过程 4.partial update优点 一. ...