链接:

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;
else
cout << "YES" << endl;
}
// for (int i = 1;i <= n;i++)
// cout << Level[i] << ' ' ;
// cout << endl;
}
} return 0;
}

最新文章

  1. BPM与 SAP &amp; Oracle EBS集成解决方案分享
  2. Write a script to check an interesting game 6174
  3. Linux System and Performance Monitoring
  4. Oracle创建定时器
  5. 理解Null,Undefined,NAN
  6. Delphi的时间处理
  7. Java常见排序算法之快速排序
  8. Ajax乱码问题
  9. 人工智能 tensorflow框架--&gt;简介及安装01
  10. Head First设计模式之访问者模式
  11. 一篇关于Maven项目的jar包Shell启动脚本
  12. 反素数ant HYSBZ - 1053(数学+dfs)
  13. ASP.NET Core 微服务初探[2]:熔断降级之Polly
  14. kafka原理和实践(三)spring-kafka生产者源码
  15. Golang入门教程(七)基本数据类型使用案例
  16. 解决Visual Studio禁止使用strlen函数的问题
  17. leetcode2
  18. luogu P1943 LocalMaxima_NOI导刊2009提高(1)
  19. [Guitar self-learning] 基本乐理知识1. 度,升降记号#/b
  20. Linux基础命令---uniq

热门文章

  1. java:struts2.3框架1(struts2快速配置,各文件之间的关系,基础代码简化版,XML中的通配符)
  2. Go语言mgo使用情况
  3. 解决 Illegal DefaultValue null for parameter type integer 异常
  4. numpy数组转置与轴变换
  5. 03: redis高级
  6. pgsql物理复制(pgsql 备库的搭建以及角色互换,提升)
  7. sql server 对数运算函数log(x)和log10(x)
  8. qt json操作
  9. vim 文本编辑器
  10. 深入理解JVM-垃圾回收器