博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1829/POJ 2492 A Bug's Life
阅读量:4316 次
发布时间:2019-06-06

本文共 3024 字,大约阅读时间需要 10 分钟。

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

Problem Description
Background 
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.
 

 

Input
The first line of the input contains the number of scenarios. Each scenario starts with one line giving the number of bugs (at least one, and up to 2000) and the number of interactions (up to 1000000) separated by a single space. In the following lines, each interaction is given in the form of two distinct bug numbers separated by a single space. Bugs are numbered consecutively starting from one.
 

 

Output
The output for every scenario is a line containing "Scenario #i:", where i is the number of the scenario starting at 1, followed by one line saying either "No suspicious bugs found!" if the experiment is consistent with his assumption about the bugs' sexual behavior, or "Suspicious bugs found!" if Professor Hopper's assumption is definitely wrong.
 

 

Sample Input
2
3 3
1 2
2 3
1 3
4 2
1 2
3 4
 

 

Sample Output
Scenario #1: Suspicious bugs found!
Scenario #2: No suspicious bugs found!
Hint
Huge input,scanf is recommended.
 
并查集题目。
记录一下当前结点到根结点的距离。 当再次找进行”并“操作时,判断属于同一根节点的两个节点到根节点的距离,同时为奇数或偶数,那么久存在矛盾。
  
/* ***********************************************Author        :pk28Created Time  :2015/8/15 9:54:22File Name     :4.cpp************************************************ */#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#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 << 61;const double eps=1e-5;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=1;i<=n+5;i++){ d[i]=0; fa[i]=i; } mark=0;}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]&1)==(d[b]&1))mark=1; 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=1; while(T--){ scanf("%d%d",&n,&m); init(); for(int i=0;i

 

 

转载于:https://www.cnblogs.com/pk28/p/4732059.html

你可能感兴趣的文章
从远程库克隆库
查看>>
codeforces Unusual Product
查看>>
hdu4348 - To the moon 可持久化线段树 区间修改 离线处理
查看>>
springMVC中一个class中的多个方法
查看>>
cxx signal信号捕获
查看>>
《Android开发艺术探索》读书笔记——Cha3.2.3改变布局参数实现View的滑动
查看>>
python闭包与装饰器
查看>>
Acegi 源码解释
查看>>
Activity的几种启动跳转方式
查看>>
LCA最近公共祖先Tarjan(离线)
查看>>
牛客练习赛16 E求值
查看>>
matlab rank
查看>>
Asp.net系列--基础篇(三)
查看>>
css基础
查看>>
如何在tomcat中如何部署java EE项目
查看>>
【Python基础教程第2版】——第二讲:列表和元组
查看>>
小常识
查看>>
使用vscode开发python
查看>>
swift--调用系统单例实现打电话
查看>>
0038-算一算是一年中的第几天
查看>>