链接:

https://vjudge.net/problem/Gym-100923H

题意:

Oberyn Martell and Gregor Clegane are dueling in a trial by combat. The fight is extremely important, as the life of Tyrion Lannister is on the line. Oberyn and Gregor are measuring their skill in combat the only way the two best fighters in Westeros can, a match of Starcraft. The one who supervises the match in none other than Por Costel the pig.

Oberyn and Gregor are both playing the Terrans, and they confront each other in the middle of the map, each with an army of Marines. Unfortunately, pigs cannot distinguish colors that well, that is why Por Costel can't figure out which marine belongs to which player. All he sees is marines in the middle of the map and, from time to time, two marines shooting each other. Moreover, it might be the case that Por Costel's imagination will play tricks on him and he will sometimes think two marines are shooting each other even though they are not.

People are starting to question whether Por Costel is the right person for this important job. It is our mission to remove those doubts. You will be given Por Costel's observations. An observation consists in the fact that Por Costel sees that marine and marine are shooting each other. We know that marines in the same team (Oberyn's or Gregor's) can never shoot each other. Your task is to give a verdict for each observation, saying if it is right or not.

An observation of Por Costel's is considered correct if, considering this observation true and considering all the correct observations up to this point true, there is a way to split the marines in "Oberyn's team" and "Gregor's team" such that no two marines from the same team have ever shot each other. Otherwise, the observation is considered incorrect.

"Elia Martell!!! You rushed her! You cheesed her! You killed her SCVs!"

思路:

带权并查集, 维护每个节点与根节点的关系,为0是友军,为1是敌军,

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#include <assert.h>
#include <iomanip>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL;const int MAXN = 1e5+10;
int Fa[MAXN], Level[MAXN];
int n, m;int GetF(int x)
{if (Fa[x] == x)return x;int tmp = Fa[x];Fa[x] = GetF(Fa[x]);Level[x] = Level[x]^Level[tmp];return Fa[x];
}
//1 1 3
//0 1 0
//1 2 3
//0 same 1 diff
int main()
{
//    freopen("meciul.in", "r", stdin);
//    freopen("meciul.out", "w", stdout);ios::sync_with_stdio(false);cin.tie(0);int t;cin >> t;while (t--){cin >> n >> m;for (int i = 1;i <= n;i++)Fa[i] = i, Level[i] = 0;int l, r;while (m--){cin >> l >> r;int tl = GetF(l);int tr = GetF(r);if (tl != tr){Level[tr] = 1^Level[l]^Level[r];Fa[tr] = tl;cout << "YES" << endl;}else{if (Level[l] == Level[r])cout << "NO" << endl;elsecout << "YES" << endl;}
//            for (int i = 1;i <= n;i++)
//                cout << Level[i] << ' ' ;
//            cout << endl;}}return 0;
}

转载于:https://www.cnblogs.com/YDDDD/p/11372646.html

Gym-100923H-Por Costel and the Match(带权并查集)相关推荐

  1. 2017乌鲁木齐区域赛I(带权并查集)

    #include<bits/stdc++.h> using namespace std; int f[200010];//代表元 long long rl[200010];//记rl[i] ...

  2. BZOJ 2303 方格染色(带权并查集)

    要使得每个2*2的矩形有奇数个红色,如果我们把红色记为1,蓝色记为0,那么我们得到了这2*2的矩形里的数字异或和为1. 对于每个方格则有a(i,j)^a(i-1,j)^a(i,j-1)^a(i-1,j ...

  3. POJ1703带权并查集(距离或者异或)

    题意:       有两个黑社会帮派,有n个人,他们肯定属于两个帮派中的一个,然后有两种操作 1 D a b 给出a b 两个人不属于同一个帮派 2 A a b 问a b 两个人关系 输出 同一个帮派 ...

  4. POJ1988(带权并查集,搬砖块)

    题意:        可以这样理解,有n快方形积木,一开始都是单独的放到哪,然后有两种操作 1 M a b 把a所在的那一堆落到b所在那一堆的上面(一开始自己是一堆) 2 C a 问a下面有多少个积木 ...

  5. LA3027简单带权并查集

    题意:       有n个点,一开始大家都是独立的点,然后给出一些关系,a,b表示a是b的父亲节点,距离是abs(a-b)%1000,然后有一些询问,每次询问一个节点a到父亲节点的距离是多少? 思路: ...

  6. hdu3234 带权并查集(XOR)

    题意:       给你n个未知的正整数,有三总操作       I P V            P的值是V       I P Q V          P XOR Q = V       Q K ...

  7. hdu4829 带权并查集(题目不错)

    题意: Information Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...

  8. poj1182 and 携程预赛2第一题 带权并查集

    题意:       动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形.A吃B, B吃C,C吃A.  现有N个动物,以1-N编号.每个动物都是A,B,C中的一种,但是我们并不知道它到底 ...

  9. How Many Answers Are Wrong HDU - 3038(带权并查集经典题,满满的都是注释)

    How Many Answers Are Wrong HDU - 3038  点击打开链接 题意:现在有n个数(你并不知道这n个数是什么),m次查询,每次查询给出u,v,w.表示从第u个数到第v个数的 ...

最新文章

  1. 利用BH1750光度传感器测量一些发光体
  2. Post Content_Length exceeds the limit
  3. Python之pandas:pandas的get_dummies函数简介(将分类变量转为哑变量)及其使用方法之详细攻略
  4. 实战ELK(9) Elasticsearch地理位置
  5. C专家编程--读书笔记十 再论指针
  6. opencv 叠加文字_Hello world.
  7. java 课程设计数据库_人事管理系统(java数据库课程设计)+SQL数据库
  8. Python3进制转换
  9. 【云周刊】第141期:阿里正式发布《Java开发手册》终极版!绝对珍藏!
  10. C语言编译过程总结简版
  11. python画pr曲线_根据Precision和recall结果画PR曲线图
  12. CloudComparePCL 主曲率、平均曲率以及高斯曲率计算
  13. 【死磕 Spring】----- IOC 之 Factory 实例化 bean
  14. arm mali 天梯图_移动处理器GPU性能天梯图数据库
  15. VHD轉換VHDX格式
  16. html和css制作的网页设计期末大作业【小米购物商城网站制作】
  17. 【转】三款免费的在线项目管理工具
  18. 红外光谱图解析知识大全(图文并茂)
  19. [基于harbor部署私有仓库] 4 推送镜像到harbor
  20. @Before,@After和@BeforeClass和@AfterClass的区别

热门文章

  1. 关于C++中的argc,argv的使用方法
  2. 仰恩大学2004年计算机系,再见,仰恩大学!谢谢你喂饱我的四年青春!
  3. mysql数据库压缩备份_Mysql备份压缩及恢复数据库方法总结
  4. linux设置BIOS串口,将x86平台的Linux控制台重定向到串口
  5. 什么Leader值得追随?
  6. Python 遍历绝对路径下的文件树搜索*.后缀打印文件绝对路径
  7. 解决python+selenium自动化,打开谷哥浏览器窗口么会自动关闭问题
  8. linux查看php服务,linux如何查看服务
  9. oracle transaction scn,关于Oracle DB SCN 生成率过高的 预警及处理建议
  10. 三种对等式网络 文件服务器,局域网的工作模式