poj 1703 Find them, Catch them 并查集
来源:互联网 发布:php 模拟post 编辑:程序博客网 时间:2024/06/16 14:00
#include <stdio.h>#define maxn 100010int p[maxn],rank[maxn];int find(int x){ if(x==p[x]) return x; else { int tmp=p[x]; p[x]=find(p[x]); rank[x]=(rank[x]+rank[tmp])%2; return p[x]; }}void link(int x,int y){ int fx=find(x); int fy=find(y); p[fx]=fy; if(rank[y]==0) rank[fx]=1-rank[x]; else rank[fx]=rank[x];}int main(){ int t; int i; int x,y; scanf("%d",&t); while(t--) { int n,m; scanf("%d%d",&n,&m); for(i=1;i<=n;i++) { p[i]=i; rank[i]=0; } char c; getchar(); for(i=1;i<=m;i++) { scanf("%c%d%d",&c,&x,&y); if(c=='D') link(x,y); else { int fx=find(x); int fy=find(y); if(fx!=fy) printf("Not sure yet.\n"); else if(rank[x]==rank[y]) printf("In the same gang.\n"); else printf("In different gangs.\n"); } getchar(); } } return 0;}
0 0
- POJ 1703 Find them, Catch them(并查集)
- POJ 1703 Find them, Catch them //并查集
- poj 1703 Find them, Catch them 并查集
- poj 1703 Find them, Catch them(并查集)
- poj 1703 Find them, Catch them //并查集
- POJ 1703 Find them, Catch them 并查集
- poj 1703 Find them, Catch them (并查集)
- poj 1703 Find them, Catch them(种类并查集)
- poj 1703 Find them, Catch them(种类并查集)
- poj 1703 -- Find them, Catch them(并查集)
- poj 1703 Find them, Catch them(并查集应用)
- POJ 1703 Find them, Catch them (并查集)
- poj 1703 - Find them, Catch them(并查集)
- poj 1703 Find them, Catch them(关系并查集)
- POJ 1703 Find them, Catch them 种类并查集
- POJ 1703 Find them, Catch them (关系并查集)
- POJ-1703 Find them, Catch them 经典并查集
- poj 1703 Find them,Catch them 并查集
- Android缓存
- Android4.2.2自增物理按键(frameworks)
- EL表达式讲解
- nandflash驱动设计
- git服务器新增用户
- poj 1703 Find them, Catch them 并查集
- 关于Algs4书中导入Stdlib.jar 和 algs4.jar包的问题
- js实现文本框textarea高度自适应
- BUG 记录: sizeof
- JSONArray和JSONObject
- Hibernate利用@DynamicInsert和@DynamicUpdate生成动态SQL语句
- DIY自己的TIPTOP显示界面
- POJ 青蛙的约会(BZOJ 1477)
- UVa 784 - Maze Exploration