hdu 1829 基础并查集,查同性恋
A Bug's Life
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 13709 Accepted Submission(s): 4449
Problem Given a list of bug interactions, decide whether the experiment supports his assumption of two genders with no homosexual bugs or if it contains some bug interactions that falsify it.
3 3
1 2
2 3
1 3
4 2
1 2
3 4
Suspicious bugs found!
Scenario #2:
No suspicious bugs found!
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=+;
int fa[maxn];
int relate[maxn];//记录与父节点的性别关系,1代表异性,0代表同性
int n,m;
int kase=;
int root(int x)
{
if(x==fa[x]) return x;
int t=root(fa[x]);
relate[x]=(relate[x]+relate[fa[x]])%;
fa[x]=t;
return fa[x];
}
void merge(int x,int y)
{
int fx=root(x);
int fy=root(y);
if(fx==fy) return;
fa[fx]=fy;
relate[fx]=(relate[y]+relate[x]+)%;
return;
}
int main()
{
int T;
int a,b;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
fa[i]=i,relate[i]=;
bool flag=false;
for(int j=;j<=m;j++)
{
scanf("%d%d",&a,&b);
if(root(a)==root(b)&&relate[a]==relate[b])
{
flag=true;
}
else merge(a,b);
//printf("yes\n");
}
//printf("dsasd\n");
printf("Scenario #%d:\n",++kase);
if(flag) printf("Suspicious bugs found!\n\n");
else printf("No suspicious bugs found!\n\n"); }
return ;
}
hdu 1829 基础并查集,查同性恋的更多相关文章
- HDU(3560)成环,并查集
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3560 并查集查有几个块,修改了之前我的一个方法(用什么map),直接判断根节点的id是i的个数. 然后 ...
- BZOJ1202 [HNOI2005]狡猾的商人 【并查集】
1202: [HNOI2005]狡猾的商人 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 4180 Solved: 2015 [Submit][S ...
- BZOJ 3319: 黑白树 并查集 + 离线 + 思维
Description 给定一棵树,边的颜色为黑或白,初始时全部为白色.维护两个操作: 1.查询u到根路径上的第一条黑色边的标号. 2.将u到v 路径上的所有边的颜色设为黑色. Notice:这 ...
- PAT Advanced A1021 Deepest Root (25) [图的遍历,DFS,计算连通分量的个数,BFS,并查集]
题目 A graph which is connected and acyclic can be considered a tree. The height of the tree depends o ...
- PAT Advanced 1013 Battle Over Cities (25) [图的遍历,统计连通分量的个数,DFS,BFS,并查集]
题目 It is vitally important to have all the cities connected by highways in a war. If a city is occup ...
- PAT Advanced 1034 Head of a Gang (30) [图的遍历,BFS,DFS,并查集]
题目 One way that the police finds the head of a gang is to check people's phone calls. If there is a ...
- 【进阶——种类并查集】hdu 1829 A Bug's Life (基础种类并查集)TUD Programming Contest 2005, Darmstadt, Germany
先说说种类并查集吧. 种类并查集是并查集的一种.但是,种类并查集中的数据是分若干类的.具体属于哪一类,有多少类,都要视具体情况而定.当然属于哪一类,要再开一个数组来储存.所以,种类并查集一般有两个数组 ...
- hdu - 1829 A Bug's Life (并查集)&&poj - 2492 A Bug's Life && poj 1703 Find them, Catch them
http://acm.hdu.edu.cn/showproblem.php?pid=1829 http://poj.org/problem?id=2492 臭虫有两种性别,并且只有异性相吸,给定n条臭 ...
- HDU 1829 A Bug's Life (种类并查集)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1829 A Bug's Life Time Limit: 15000/5000 MS (Java/Oth ...
随机推荐
- iOS开发之WKWebView简单使用
iOS开发之WKWebView简单使用 iOS开发之 WKWebVeiw使用 想用UIWebVeiw做的,但是突然想起来在iOS8中出了一个新的WKWebView,算是UIWebVeiw的升级版. ...
- 破解简单Mifare射频卡密钥杂记
先要了解一点大学城浴卡用的是什么卡,经查证是Mifare S50卡,也有叫ISO14443A的(协议名).本来想看看大学城浴卡有没有安全漏洞,没想到浴卡公司在安全性上几乎是蔑视我们大学生的智商,虽然被 ...
- Qt自定义事件的实现(军队真正干活,但要增加监军,大平台通知事件,事件内容自定义)
初学Qt,用了Qt自带的事件,然后想怎么才能定义自己的事件呢?又如何使用自定义事件呢?看了篇文章,说先要子类化QEvent,然后定义自己的QEvent::Type,然后重写QWidget::event ...
- windows环境下VS2013编译openSSL
openssl版本:1.0.2h 编译器:MSVC (VS2013) 需要准备工具:perl. windows环境的perl下载请戳这里:http://www.activestate.com/acti ...
- java数据安全(一)
在java开发中,常常需要考虑数据安全问题,然不仅仅需要考虑数据存储的安全,还需要考虑数据的传输安全.自从有了数据安全问题后,密码学也就出来了.了解数据安全,首先需要了解密码学 1.什么是密码学 密码 ...
- BZOJ 1007 [HNOI2008]水平可见直线
1007: [HNOI2008]水平可见直线 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 4453 Solved: 1636[Submit][Sta ...
- POJ 1122 FDNY to the Rescue! Floyd 打印路径就行了
题目大意: 纽约消防部门的支援速度是值得纽约人骄傲的一件事.但是他们想要最快的支援速度,帮助他们提升支援速度他们要调度离着火点最近的一个消防站.他们要你写一个程序来维护纽约消防站的光荣传统.软件需要有 ...
- HDU2056(rectangles)
Rectangles Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- Selenium webdriver 开始
最早接触的selenium是 selenium IDE,当时是为了准备论文.为了用IDE还下载了Firefox浏览器.后来接触过两个项目都需要selenium,一个采用selenium webdirv ...
- maven,本地仓库和私服nexus的配置,以及eclipse载入maven
首先可以进入http://maven.apache.org/官网查看如何配置 一.配置环境 1 确定自己的java运行环境配置正确-->在cmd运行 java -version或echo %JA ...