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 ...
随机推荐
- js -“=”“==”和“===”的区别
这个问题再面试中经常被问到,说实话我都是懵的,一个“=”和两个“==”等的区别我还是知道的,就是三个“===”我完全是不知道的,因为我基本上都没有遇到过且用到过,所以再这个问题上我是没分的,人家考官就 ...
- 洛谷—— P1875 佳佳的魔法药水
https://www.luogu.org/problemnew/show/1875 题目背景 发完了 k 张照片,佳佳却得到了一个坏消息:他的 MM 得病了!佳佳和大家一样焦急 万分!治好 MM 的 ...
- luogu P1018 乘积最大
题目描述 今年是国际数学联盟确定的"2000――世界数学年",又恰逢我国著名数学家华罗庚先生诞辰90周年.在华罗庚先生的家乡江苏金坛,组织了一场别开生面的数学智力竞赛的活动,你的一 ...
- JDBC工具类 访问数据库 增删改查CRUD的通用方法
1 package com.zmh.util; 2 3 import java.sql.*; 4 import java.util.ArrayList; 5 import java.util.Hash ...
- 【windows】windows下的hosts文件位置
- Hibernate注解详解
一.实体Bean 每个持久化POJO类都是一个实体Bean, 通过在类的定义中使用 @Entity 注解来进行声明. 声明实体Bean @Entitypublic class Flightimplem ...
- ant的安装和配置
1.从官网下载bin源码 http://ant.apache.org/bindownload.cgi#Verify%20Releases 校验源码的完整性 2.直接把解压,然后把文件放入/usr/lo ...
- 这一篇里面有很多关于scala的list的操作的好的知识
https://www.cnblogs.com/weilunhui/p/5658860.html 1.++[B] 在A元素后面追加B元素 1 2 3 4 5 6 7 8 9 10 11 12 13 ...
- .NET组件编程
链接 http://www.cnblogs.com/mapserver/archive/2006/03/06/343632.html
- 实践认识--ANN
1. 常用激活函数 激活函数的选择是构建神经网络过程中的重要环节,下面简要介绍常用的激活函数. (1) 线性函数 ( Liner Function ) (2) 斜面函数 ( Ramp Functio ...