Por Costel and the Match Gym - 100923H

题目链接: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!"


Input

The input file meciul.in will contain, on its first line, the number of tests (). A test has the following structure: the first line contains integers () and () and the next lines each contain a pair of integers and () describing an observation of Por Costel's.

Output

The output file meciul.out will contain one line for each of Por Costel's observations, on each test. The line will contain "YES" if the observation is correct and "NO" otherwise. It is not necessary to leave extra spacing between the outputs of different test cases.

Example

Input
13 31 22 31 3

Output
YESYESNO题意:每次给你两个数,是敌人情况,输出“YES”;一旦遇到不是敌人情况,输出“NO”;思路:一开始以为就是单纯的并查集模板题,后来想到之前做过一题它有多种情况,所以类似这个,比如1,2,3,4,共有4个人,1和4是敌人关系,那么这时我们再引出四个人,一共有8个人,12345678,1和4是敌人关系,那么5和8也是敌人关系,那么1和5就是友人关系,4和8就是友人关系,1和2再是敌人关系,那么5和6就是敌人关系,这时候1和5还是友好关系,2和6就是友好关系,这样关系就不会出现矛盾的情况
 
//
// Created by HJYL on 2019/8/15.
//
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
using namespace std;
typedef long long ll;
const int maxn=1e6+10;
int father[maxn];
int p[maxn];
struct Node{int x,y;
}node[maxn];
int find(int x)
{if(x==father[x])return x;return father[x]=find(father[x]);
}
void merge(int x,int y)
{int fx=find(x);int fy=find(y);if(fx!=fy)father[fx]=fy;
}
int main()
{//freopen("C:\\Users\\asus567767\\CLionProjects\\untitled\\text","r",stdin);freopen("meciul.in","r",stdin);freopen("meciul.out","w",stdout);int T;scanf("%d",&T);while(T--){int n,m;scanf("%d%d",&n,&m);for(int i=1;i<=(n<<1);i++)father[i]=i;int x,y;for(int i=0;i<m;i++){scanf("%d%d",&x,&y);int xx=find(x);int yy=find(y);if(xx==yy)printf("NO\n");else{merge(x,y+n);merge(x+n,y);printf("YES\n");}}}return 0;
}



转载于:https://www.cnblogs.com/Vampire6/p/11373386.html

Por Costel and the Match Gym - 100923H(经典种类并查集)相关推荐

  1. 食物链(经典种类并查集问题)---详解

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

  2. POJ1182 食物链---(经典种类并查集)

    题目链接:http://poj.org/problem?id=1182 食物链 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: ...

  3. I - Por Costel and the Pairs Gym - 100923I _思维啊——可惜我现在还没

    We don't know how Por Costel the pig arrived at FMI's dance party. All we know is that he did. The d ...

  4. Gym100923H Por Costel and the Match

    题目链接:http://codeforces.com/gym/100923/problem/H 分析:并查集,用enemy储存x的敌人,用weight储存权重决定根节点 需用scanf和puts输入输 ...

  5. 经典算法-并查集、快速排序、字典序算法、二分搜索、牛顿开方法、求质数(筛选法)、编辑距离、滑动窗口、异或求重、长除法

    目录 ​​​​​​​​​​​​​​ 并查集 快速排序 字典序算法 二分搜索 开根号-牛顿开方法 求质数 编辑距离 滑动窗口 异或求重 长除法 ​​​​​​​ 并查集 并查集用于解决相同元素集合动态连接 ...

  6. Friendly Group Gym - 102769F 2020(并查集)ccpc秦皇岛分站赛

    题意: n个学生要组成一个小组参加会议(可以不参加), 1.对于每两个朋友(x ,y),如果他们俩都参加会议,该小组的友好价值将会增加 1:如果其中只有一位参加会议,则该组的友好价值将降低 1. 3. ...

  7. 【POJ - 1182】 食物链(附超详细讲解)(并查集--种类并查集经典题)

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

  8. Gym - 101194G Pandaria (并查集+倍增+线段树合并)

    题意: 给定一个无向图.每个点有一种颜色.现在给定q个询问,每次询问x和w,求所有能通过边权值不超过w的边走到x的点的集合中,哪一种颜色的点出现的次数最多.次数相同时输出编号最小的那个颜色.强制在线. ...

  9. Gym-100923H-Por Costel and the Match(带权并查集)

    链接: https://vjudge.net/problem/Gym-100923H 题意: Oberyn Martell and Gregor Clegane are dueling in a tr ...

最新文章

  1. Python xlrd 读取excel表格 常用用法整理
  2. 常见的网络***有哪些?
  3. react不同环境不同配置angular_DevOps 前端项目(angular、vue、react)打包静态资源生成一份Docker镜像支持部署不同环境...
  4. CTF-PWN环境搭建
  5. tomcat 绑定ipv4端口
  6. 修改服务器mysql密码,修改Linux服务器中的MySql密码
  7. 什么是CPU密集型、IO密集型?
  8. python之虚拟环境
  9. BZOJ1832: [AHOI2008]聚会
  10. android之uniapp从0开始离线打包
  11. 三年一个人使用虚幻引擎(UDK)开发的一个游戏心路
  12. Windows 10 Enterprise LTSC 2019 (x64) 版本 (安装+激活+添加系统邮箱)
  13. spring aop切面执行顺序
  14. jzxx1105 【入门】字符图形4-星号正三角
  15. MySQL 查询各科前三名
  16. ssl免费证书获取,并在nginx服务器上安装ssl证书,以及docker安装nginx需注意的细节。
  17. Gesture-Recognition
  18. pyecharts查看版本_pyecharts 安装及使用指南
  19. Android VideoView播放 项目中的 视频文件 自动横屏 全屏播放
  20. 限速linux c语言,基于Linux系统的流量控制程序的C语言代码

热门文章

  1. android aidl编译,Android AIDL详解
  2. linux grub关闭 fsck,手把手教你安全运行fsck命令
  3. SpringMVC详细介绍 zh-Maven高级(5)
  4. java常用开发框架
  5. JNA粗浅的一些讲解
  6. 铸铁的弹性模量和泊松比_常用材料的弹性模量及泊松比数据表
  7. 应对老板的“黑”情绪
  8. Hexo+yilia添加helper-live2d插件实现宠物动画
  9. macOS 系统Evernote(印象笔记) 迁移到语雀
  10. logo像闪电的html编译器,基于Html5 Canvas绘制逼真的闪电动画特效