hdoj--1829--A Bug's Life(带权并查集)
来源:互联网 发布:云led控制软件 编辑:程序博客网 时间:2024/06/06 11:28
A Bug's Life
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 12677 Accepted Submission(s): 4142
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.
Source
TUD Programming Contest 2005, Darmstadt, Germany
Recommend
linle | We have carefully selected several similar problems for you: 1558 1811 1198 1856 1325
//题意:给出了1--n的m种关系,x--y中x跟y的性别未知,问有没有可能出现同性恋//一道带权并查集问题, 不要考虑x,y的性别是男是女,只需要考虑他们的性别//是否一致, vis数组存放爱人的性别,//举例子:x--y说明x和y有关系 //如果说vis[x]不为零说明x有了爱人,并且vis[x]存放的就是他爱人的性别,//那么 那么y一定跟vis[x]是一个集合中的,不需要管vis存放的都是什么数字 #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define MAXN 10000010int n,m,flag;int vis[MAXN],pre[MAXN];void init(){for(int i=0;i<=n;i++){vis[i]=0;pre[i]=i;}}int find(int x){if(pre[x]!=x)pre[x]=find(pre[x]);return pre[x];}void join(int x,int y){int fx=find(x);int fy=find(y);if(fx==fy)flag=1;else{if(vis[fx])//如果说fx已经有了爱人,那么fy的性别一定要和fx性别一样 pre[vis[fx]]=fy;if(vis[fy])pre[vis[fy]]=fx; vis[fx]=fy;vis[fy]=fx;//vis存放爱人的性别,fx爱人的性别是fy //如果说两人性别不属于同一结合,两人可以相恋 }}int main(){int t,k=1;scanf("%d",&t);while(t--){scanf("%d%d",&n,&m);init();flag=0;int x,y;for(int i=0;i<m;i++){scanf("%d%d",&x,&y);join(x,y);}printf("Scenario #%d:\n",k++);if(flag)printf("Suspicious bugs found!\n\n");elseprintf("No suspicious bugs found!\n\n");}return 0;}
0 0
- hdoj--1829--A Bug's Life(带权并查集)
- HDOJ 1829 A Bug's Life (并查集)
- hdoj 1829 A Bug's Life 【带权并查集】
- A Bug's Life(带权并查集)
- HDOJ 1829 A Bug's Life (并查集)
- (并查集)A Bug's Life -- HDOJ
- A bug's life(带权并查集)
- HDU 1829 A Bug's Life(带权并查集)
- HDU 1829 A Bug‘s Life 带权并查集&&带偏移量的写法
- HDOJ 题目1829A Bug's Life(分组并查集)
- HDOJ 1829 A Bug's Life (种类并查集)
- hdoj-1289-A Bug's Life【种类并查集】
- HDU-1829 A Bug's Life (带权并查集)
- hdu 1829 A Bug's Life(带权并查集)
- POJ 2492/hdu 1829 A Bug's Life【带权并查集】
- HDU 1829 A Bug's Life 带权并查集
- HDU 1829 A Bug's Life 经典带权并查集
- HDU 1829 A Bug's Life(带关系的并查集)
- The vertically scrolling ScrollView should not contain another vertically scrolling widget (ListView
- 对称加密 非对称加密 不可逆加密算法
- 如何将word文件转化为Latex文件:word-to-latex-2.56详解
- HDOJ 5616 Jam's balance (暴力)
- HDU1754 线段树
- hdoj--1829--A Bug's Life(带权并查集)
- CSS
- 移动端 h5开发相关内容总结(三)
- mac制作iso文件
- librtmp 以record方式向red5推送直播流
- deep learning tutorial 翻译 (theano学习指南3(翻译)-多层感知器模型)
- iOS开发之Objective-c的MD5/SHA1加密算法的实现
- 【英语】happy new year !
- Angularjs指令参数