POJ2492 A Bug's Life
来源:互联网 发布:mac怎么设置屏幕背景 编辑:程序博客网 时间:2024/05/23 15:45
http://poj.org/problem?id=2492
搞基题啊我操,给的就是n个虫子,m对虫子发生过关系 然后问有没有虫子是同性恋。。。
并查集,需要用t数组保存x对f[x]的关系,0为同性,1为异性。
#include <cstdio>#include <cstring>#include <cmath>#include <map>#include <set>#include <vector>#include <iostream>#include <algorithm>#include <queue>using namespace std;const double eps=1e-8;const double INF=1e50;//const double pi=acos(-1);#define N 2005#define M 1000005int f[N],n,m,t[N];int find(int x){ if (f[x]==x) return x; int fx=f[x]; f[x]=find(f[x]); t[x]=(t[x]+t[fx])%2;//这里不可t[x]=(t[x]+t[f[x]])%2 return f[x];}int main(){ freopen("a","r",stdin); int i,k,T,a,b; scanf("%d",&T); for (int kk=1;kk<=T;kk++) { if (kk>1) printf("\n"); printf("Scenario #%d:\n",kk); scanf("%d%d",&n,&m); for (i=1;i<=n;i++) { f[i]=i; t[i]=0; } bool flag=true; for (k=1;k<=m;k++) { scanf("%d%d",&a,&b); int fa=find(a),fb=find(b); if (fa==fb) { if (t[a]==t[b]) flag=false; } else { f[fb]=fa; t[fb]=(t[b]+t[a]+1)%2; } } if (flag==true) printf("No suspicious bugs found!\n"); else printf("Suspicious bugs found!\n"); } return 0;}
- poj2492 A Bug's Life
- POJ2492 A Bug's Life
- poj2492 - A Bug's Life
- poj2492 A Bug's Life
- POJ2492 A Bug's Life
- POJ2492---A Bug's Life
- poj2492 A Bug's Life
- POJ2492 A Bug's Life
- POJ2492-A Bug's Life
- poj2492——A Bug's Life
- POJ2492——A Bug's Life
- HDU1829 POJ2492 A Bug's Life
- poj2492——A Bug's Life
- POJ2492--A Bug's Life--并查集
- poj2492 A Bug's Life 种类并查集
- POJ2492 A Bug's Life (并查集)
- poj2492--A Bug's Life(并查集变形)
- POJ2492 A Bug's Life 【并查集】
- SAP MM之移动类型(Movement type-MVT)
- 《Hadoop The Definitive Guide》ch09 Setting Up a Hadoop Cluster
- 筛选法输出100以内的所有素数
- 《Hadoop The Definitive Guide》ch10 Administering Hadoop
- yum chrome
- POJ2492 A Bug's Life
- QTP_QTP学习笔记(1)
- 用Wi-Fi,谁说一定要有热点?
- redis培训学习总结
- C#语言cts类型
- 关于一个int *ptr=(int *)(&a+1)问题的探讨
- 互斥锁
- 单链表--操作总结
- 关于网关的精典描述通俗易懂