HDU 1829/POJ 2492 A Bug's Life
A Bug's Life
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11981 Accepted Submission(s): 3901
Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gender. In his experiment, individual bugs and their interactions were easy to identify, because numbers were printed on their backs.
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.
Suspicious bugs found!
No suspicious bugs found!
Huge input,scanf is recommended.
- /* ***********************************************
- Author :pk28
- Created Time :2015/8/15 9:54:22
- File Name :4.cpp
- ************************************************ */
- #include <iostream>
- #include <cstring>
- #include <cstdlib>
- #include <stdio.h>
- #include <algorithm>
- #include <vector>
- #include <queue>
- #include <set>
- #include <map>
- #include <string>
- #include <math.h>
- #include <stdlib.h>
- #include <iomanip>
- #include <list>
- #include <deque>
- #include <stack>
- #define ull unsigned long long
- #define ll long long
- #define mod 90001
- #define INF 0x3f3f3f3f
- #define maxn 3000+10
- #define cle(a) memset(a,0,sizeof(a))
- const ull inf = 1LL << ;
- const double eps=1e-;
- using namespace std;
- bool cmp(int a,int b){
- return a>b;
- }
- int fa[maxn];
- int d[maxn];
- int n,m,mark;
- void init(){
- for(int i=;i<=n+;i++){
- d[i]=;
- fa[i]=i;
- }
- mark=;
- }
- int findfa(int x){
- if(x==fa[x])return x;
- else{
- int root=findfa(fa[x]);
- d[x]+=d[fa[x]];//记录到根节点的距离
- fa[x]=root;
- return fa[x];
- }
- }
- void Union(int a,int b){
- int x=findfa(a);
- int y=findfa(b);
- if(x==y){
- if((d[a]&)==(d[b]&))mark=;
- return ;
- }
- else{
- fa[x]=y;
- d[x]=(1+d[b]-d[a]);//向量
- }
- }
- int main()
- {
- #ifndef ONLINE_JUDGE
- freopen("in.txt","r",stdin);
- #endif
- //freopen("out.txt","w",stdout);
- int T;
- cin>>T;
- int a,b;
- int cnt=;
- while(T--){
- scanf("%d%d",&n,&m);
- init();
- for(int i=;i<m;i++){
- scanf("%d %d",&a,&b);
- if(mark)continue;
- Union(a,b);
- }
- printf("Scenario #%d:\n",cnt++);
- if(mark)printf("Suspicious bugs found!\n");
- else printf("No suspicious bugs found!\n");
- printf("\n");
- }
- return ;
- }
HDU 1829/POJ 2492 A Bug's Life的更多相关文章
- 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 &poj 2492 A Bug's Life(推断二分图、带权并查集)
A Bug's Life Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- POJ 2492 A Bug's Life(并查集)
http://poj.org/problem?id=2492 题意 :就是给你n条虫子,m对关系,每一对关系的双方都是异性的,让你找出有没有是同性恋的. 思路 :这个题跟POJ1703其实差不多,也是 ...
- (简单) POJ 2492 A Bug's Life,二分染色。
Description Background Professor Hopper is researching the sexual behavior of a rare species of bugs ...
- POJ 2492 A Bug's Life(带权并查集)
题目链接:http://poj.org/problem?id=2492 题目大意:有n只虫子,m对关系,m行每行有x y两个编号的虫子,告诉你每对x和y都为异性,先说的是对的,如果后面给出关系与前面的 ...
- POJ 2492 A Bug's Life
传送门:A Bug's Life Description Background Professor Hopper is researching the sexual behavior of a rar ...
- POJ 2492 A Bug's Life (并查集)
A Bug's Life Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 30130 Accepted: 9869 De ...
- POJ 2492 A Bug's Life (并查集)
Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...
- POJ 2492 A Bug's Life【并查集高级应用+类似食物链】
Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...
随机推荐
- 重复造轮子之RSA算法(一) 大素数生成
出于无聊, 打算从头实现一遍RSA算法 第一步, 大素数生成 Java的BigInteger里, 有个现成的方法 public static BigInteger probablePrime(int ...
- R语言实战读书笔记(十三)广义线性模型
# 婚外情数据集 data(Affairs, package = "AER") summary(Affairs) table(Affairs$affairs) # 用二值变量,是或 ...
- Codeforces 375D Tree and Queries(DFS序+莫队+树状数组)
题目链接 Tree and Queries 题目大意 给出一棵树和每个节点的颜色.每次询问$vj, kj$ 你需要回答在以$vj$为根的子树中满足条件的的颜色数目, 条件:具有该颜色的节点数量至少 ...
- 如何轻松的把图片导入execl表格中
在项目中有时候会遇到往数据库中导数据的时候,往往需要把图片也一起导入execl表格中,那怎么才能把图片一块导入至execl中呢?那么今天我们就来看看怎么实现吧! 如何实现?今天我们就来用jxl和poi ...
- kafka技术分享01--------why we study kafka?
kafka技术分享01--------why we study kafka? 作为一名大数据工程师,我们所面对的大多数是数据密集型的应用,而非计算密集型的应用.对于数据密集型的应用,如何解决数据激 ...
- SqlServer 并发事务:死锁跟踪(三)6种跟踪死锁的方法总结 大神
http://blog.csdn.net/kk185800961/article/details/42504857
- pt-pmp :pt toolkit
http://www.cnblogs.com/ivictor/p/6012183.html
- DELPHI跨平台编译开关
DELPHI跨平台编译开关 DELPHI 现在是跨平台的开发工具,已经不仅仅针对WINDOWS OS. 跨平台的时候,一些WINDOWS特有的API或语法是不能用的,必须使用跨平台的新语法,要用编译开 ...
- jenkins执行单元测试,会产生大量临时文件,要及时删除,不然会把inode耗尽
jenkins的build命令:clean test -U findbugs:findbugs pmd:pmd sonar:sonar -Djava.io.tmpdir=/tmp/ -Dsonar.p ...
- DICOM医学图像处理:Deconstructed PACS之Orthanc,Modification & Anonymization
背景: 上篇博文为引子,介绍了一款神奇的开源PACS系统——Orthanc.本篇开始解读官方Cookbook中的相关内容,对于简单的浏览.访问和上传请阅读前篇博文.在常规的PACS系统中还未出现对于D ...