hdu 1829
来源:互联网 发布:淘宝红号查询 编辑:程序博客网 时间:2024/03/29 13:03
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!
Hint
Huge input,scanf is recommended.
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;int pre[2100];int sex[2100];int find(int x){ int r=x; while(pre[r]!=r) { r=pre[r]; } int i=x,j; while(i!=r) { j=pre[i]; pre[i]=r; i=j; } return r;}void join(int x,int y){ int fx=find(x),fy=find(y); if(fx!=fy) pre[fx]=fy;}int main(){ int t,n,m,a,b,flag,num=1; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); memset(sex,0,sizeof(sex)); for(int i=1;i<=n;i++) { pre[i]=i; } flag=0; for(int i=1;i<=m;i++) { scanf("%d%d",&a,&b); if(flag==1) continue; if(find(a)==find(b)) { flag=1; continue; } if(sex[a]==0) sex[a]=b; else join(sex[a],b); if(sex[b]==0) sex[b]=a; else join(sex[b],a); } if(flag==1) { printf("Scenario #%d:\n",num); printf("Suspicious bugs found!\n"); printf("\n"); } else { printf("Scenario #%d:\n",num); printf("No suspicious bugs found!\n"); printf("\n"); } num++; } return 0;}
0 0
- hdu 1829
- hdu 1829
- hdu 1829
- HDU 1829
- hdu 1829
- HDU 1829
- HDU-1829
- HDU 1829
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- 在Activity的oncreate方法中如果跳转到别的activity,会发生什么
- 在Word中选择多个自选图形对象
- NYOJ--40--公约数和公倍数
- JAVA的整型与字符串相互转换
- 浅析Java中的反射机制原理
- hdu 1829
- UVa11038 How Many O's? (计数)
- 同步与异步的初步理解
- 让windows8 变成无线路由器的方法
- Leetcode51 N-Queens
- Sed简介
- 【Java多线程】之十:Timer and TimerTask
- Swift调用C代码的方法
- 华为上机 循环报数 java