HDU 1829 A Bug's Life
来源:互联网 发布:姜夔 扬州慢 知乎 编辑:程序博客网 时间:2024/05/22 17:19
思路:并查集、只有两个集合、非此即彼
#include<stdio.h>#include<iostream>#include<string.h>#include<algorithm>using namespace std;const int maxn=1000005;int n,m;int father[maxn];int sex[maxn];void init(){ for(int i=1;i<=n;i++) father[i]=i;}int find(int x){ while(x!=father[x]) x=father[x]; return father[x];}void merge(int x,int y){ int fx=find(x); int fy=find(y); if(fx==fy)return; else { father[fy]=fx; return; }}int main(){ int t; scanf("%d",&t); int flag; int cas=1; while(t--) { flag=0; scanf("%d%d",&n,&m); init(); memset(sex,0,sizeof(sex)); for(int i=1;i<=m;i++) { int a,b; scanf("%d%d",&a,&b); if(!flag) { a=find(a); b=find(b); if(a==b)flag=1; if(sex[a]==0)sex[a]=b; else merge(sex[a],b); if(sex[b]==0)sex[b]=a; else merge(sex[b],a); } } if(flag) { printf("Scenario #%d:\n",cas++); printf("Suspicious bugs found!\n"); } else { printf("Scenario #%d:\n",cas++); printf("No suspicious bugs found!\n"); } printf("\n"); } return 0;}
0 0
- hdu 1829 A Bug's Life
- HDU 1829 A Bug's Life
- hdu 1829 A Bug's Life
- hdu 1829 A Bug's Life
- HDU 1829 A Bug's Life
- HDU 1829 A Bug's Life
- hdu 1829 A Bug's Life
- hdu 1829 A Bug's Life
- hdu 1829 A Bug's Life
- hdu 1829 A Bug's Life
- HDU 1829 A Bug's Life
- HDU 1829 A Bug's Life
- HDU 1829 A Bug's Life
- hdu 1829 A bug’s life
- HDU 1829 A Bug's Life
- HDU 1829 A Bug's Life
- HDU 1829 A Bug's Life
- A Bug's Life-HDU-1829
- DP状态设计与方程总结-目录
- hibernate java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z
- Android 打开软键盘 关闭软键盘
- 女子住院输血后夫妻相继染艾滋 医院赔30余万元
- 记录ab蓝学网新改版完成
- HDU 1829 A Bug's Life
- php setcookie函数参数说明与用法
- 倦笔如椽
- 实用的七个程序段
- c#中多线程写DataGridView出现滚动条导致程序卡死(无响应)的解决办法
- 类的组合
- 动态规划之最长公共子序列
- 关于类的sizeof()
- 【ZJOI2007】仓库建设