poj 2492
来源:互联网 发布:合并pdf软件 编辑:程序博客网 时间:2024/06/05 11:06
思路差不多,但要去判断同性恋
自己手写在Union()写错了
注意格式
r[fx]=(r[x]+1+r[y])%2; //fx与x关系 + x与y的关系 + y与fy的关系 = fx与fy的关系
这种叫种类并查集;
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>using namespace std;const int maxn=2005;int p[maxn],r[maxn]; //0为同类,1为异类 int Find(int x){if(x==p[x]) return x;int t=p[x];p[x]=Find(p[x]);r[x]=(r[x]+r[t])%2;return p[x];}void Union(int x,int y){int fx=Find(x);int fy=Find(y);p[fx]=fy;r[fx]=(r[x]+r[y]+1)%2; //fx与x关系 + x与y的关系 + y与fy的关系 = fx与fy的关系}int main(){int t,cnt=0;scanf("%d",&t);while(t--){int n,m,a,b;scanf("%d%d",&n,&m);for(int i=1;i<=n;i++){p[i]=i; r[i]=0;}int flag=0; for(int i=0;i<m;i++){scanf("%d%d",&a,&b);if(Find(a)==Find(b)&&r[a]==r[b]){flag=1;}else {Union(a,b);}}if(flag==1) {printf("Scenario #%d:\n",++cnt);printf("Suspicious bugs found!\n\n");}else{printf("Scenario #%d:\n",++cnt);printf("No suspicious bugs found!\n\n");}} }
阅读全文
0 0
- poj 2492 && poj 1703
- POJ 2492
- POJ 2492
- poj-2492
- POJ 2492
- POJ 2492
- poj 2492
- POJ 2492 2-sat
- poj 2492 生物实验
- POJ-2492(DFS)
- POJ 2492 解题报告
- POJ 2492 虫子交配
- POJ
- poj
- POJ
- POJ
- poj
- poj
- Java websocket + redis 实现多人单聊天室,多人多聊天室, 一对一聊天
- dp day2-背包
- Python 文件操作
- WebService的工作原理及实例
- Caffe 在 win10 环境下配置
- poj 2492
- python爬取数据
- u-boot回顾(二)
- 回归分析
- Ubuntu下设置静态IP
- H5+CSS3设计动态的首页背景
- 自建二叉树,及收获的经验
- text文本框, textarea文本域 框内提示文字
- 特殊密码锁