直接解释输入了:

第一行cases.

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

给你两个空的集合

每个操作后面跟着俩数

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

A操作问这俩数什么关系

不能确定:输出Not sure yet.

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

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

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

  1. // by SiriusRen
  2. #include <cstdio>
  3. #include <cstring>
  4. using namespace std;
  5. int cases,xx,yy,n,m,f[105000],d[100500];
  6. char jy,jy1;
  7. int find(int x){
  8. if(f[x]==x)return x;
  9. int y=f[x];
  10. f[x]=find(f[x]);
  11. d[x]=(d[x]+d[y])%2;
  12. return f[x];
  13. }
  14. int main(){
  15. scanf("%d",&cases);
  16. while(cases--){
  17. scanf("%d%d",&n,&m);
  18. for(int i=1;i<=n;i++)f[i]=i;
  19. memset(d,0,sizeof(d));
  20. for(int i=1;i<=m;i++){
  21. scanf("%c%c%d%d",&jy1,&jy,&xx,&yy);
  22. int fx=find(xx),fy=find(yy);
  23. if(jy=='A'){
  24. if(fx!=fy)puts("Not sure yet.");
  25. else if(d[xx]!=d[yy])puts("In different gangs.");
  26. else puts("In the same gang.");
  27. }
  28. else f[fx]=fy,d[fx]=(d[yy]-d[xx]+1)%2;
  29. }
  30. }
  31. }

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. SLAM: Ubuntu14.04_Kylin安装ROS-Indigo

    参考连接:ROS-Indigo版在Ubuntu上的安装第一步: 软件源配置 1. 增加下载源(增加ubuntu版的ros数据仓库,即下载源)(通用指令适合任何版本的ros) sudo sh -c 'e ...

  2. dispatch_sync

    dispatch_sync does two things: queue a block blocks the current thread until the block has finished ...

  3. Combobox 下拉框赋值

    string sql = "select distinct RoleName from tb_Role"; DataTable dt = SqlHelper.DataTable(s ...

  4. 深入了解Spring Boot 核心注解原理

    SpringBoot目前是如火如荼,所以今天就跟大家来探讨下SpringBoot的核心注解@SpringBootApplication以及run方法,理解下springBoot为什么不需要XML,达到 ...

  5. 【剑指Offer】60、把二叉树打印成多行

      题目描述:   从上到下按层打印二叉树,同一层结点从左至右输出.每一层输出一行.   解题思路:   本题可类比第22题:从上往下打印二叉树,这两道题实际上是一回事,只不过这里我们多了一个分行打印 ...

  6. 【剑指Offer】6、旋转数组的最小数字

      题目描述:   把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 输入一个非减排序的数组的一个旋转,输出旋转数组的最小元素. 例如数组{3,4,5,1,2}为{1,2,3,4,5 ...

  7. 关于node对文件的读取

    设计: 通过终端git / cmd 获取用户输入路径,然后遍历路径下所有的文件,打印输出. 因为需要命令行交互,所以引入prompt库 (https://github.com/flatiron/pro ...

  8. 博弈论题目总结(二)——SG组合游戏及变形

    SG函数 为了更一般化博弈问题,我们引入SG函数 SG函数有如下性质: 1.如果某个状态SG函数值为0,则它后继的每个状态SG函数值都不为0 2.如果某个状态SG函数值不为0,则它至少存在一个后继的状 ...

  9. [luogu2587 ZJOI2008] 泡泡堂 (贪心)

    传送门 Description 第XXXX届NOI期间,为了加强各省选手之间的交流,组委会决定组织一场省际电子竞技大赛,每一个省的代表队由n名选手组成,比赛的项目是老少咸宜的网络游戏泡泡堂.每一场比赛 ...

  10. open-ldap服务安装(1)

    LDAP简介 LDAP 代表 轻量级目录访问协议.在我的理解中ldap就是一个数据库. 在LDAP中,目录条目以分层树状结构排序. 传统上,这种结构反映了地理和组织边界,表示国家/地区的条目显示在树的 ...