HDU1829- A Bug's Life
来源:互联网 发布:mac怎么把两个窗口 编辑:程序博客网 时间:2024/06/02 00:22
A Bug's Life
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 15661 Accepted Submission(s): 5124
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.
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
23 31 22 31 34 21 23 4
Sample Output
Scenario #1:Suspicious bugs found!Scenario #2:No suspicious bugs found!HintHuge input,scanf is recommended.
#include<stdio.h>#define maxn 4020int per[maxn],rank[maxn];int find(int x){ int r=x; while(per[r]!=r) { r=per[r]; } int i=x,j; while(i!=r) { j=per[i]; per[i]=r; i=j; } return r;}void join(int x,int y){ x=find(x); y=find(y); if(x==y) return; if(rank[x]<rank[y]) { per[x]=y; } else { per[y]=x; if(rank[x]==rank[y]) rank[x]++; }}bool same(int x,int y){ if(find(x)==find(y)) return true; else return false;}int main(){ int n,i; scanf("%d",&n); for(i=1;i<=n;i++) { int a,b,flag,j; scanf("%d%d",&a,&b); for(j=1;j<=2*a;j++) { per[j]=j; rank[j]=1; } flag=0; while(b--) { int x,y; scanf("%d%d",&x,&y); if(same(x,y)||same(x+a,y+a)) { flag=1; } else { join(x,y+a); join(x+a,y); } } printf("Scenario #%d:\n",i); if(flag==1) printf("Suspicious bugs found!\n"); else printf("No suspicious bugs found!\n"); printf("\n"); }}
阅读全文
0 0
- hdu1829 A Bug's Life
- hdu1829 A Bug's Life
- hdu1829 A Bug's Life
- hdu1829 A Bug's Life
- HDU1829- A Bug's Life
- hdu1829 a bug's life
- HDU1829 POJ2492 A Bug's Life
- HDU1829 A Bug's Life 并查集
- HDU1829(A Bug's Life )—并查集
- A Bug's Life hdu1829 并查集
- A Bug's Life(hdu1829种类并查集)
- hdu1829 A Bug's Life (并查集)
- hdu1829 A Bug's Life 并查集
- hdu1829 A Bug's Life(并查集)
- HDU1829 - A Bug's Life 分组并查集
- hdu1829 A Bug's Life --分组并查集
- HDU1829:A Bug's Life(并查集)
- HDU1829:A Bug's Life(种类并查集)
- 1052. Linked List Sorting 解析
- nodejs学习笔记-1-express
- Gson 反序列化Map<String, Object>类型的小问题
- CP2K中GPW和GAPW的一些区别
- Perfect Squares
- HDU1829- A Bug's Life
- HDUOJ 1160 Leftmost Digit
- Redis异常分析-输入缓冲区过大
- 【算法】排序算法第二讲:选择排序
- K9F2G08U0C NAND FLASH 的地址分析
- 几种常见树形数据结构小结
- ZZULIOJ 1726 状态压缩 bfs
- 肺结节评估
- 多线程之RunLoop