poj 1988 Cube Stacking
2015-03-15 23:56
316 查看
不多说了,傻逼的一道题。。。
#include<stdio.h> const int M = 30005; int pa[M],cnt[M],dist[M]; void Init() { for (int i = 1;i <= M;i ++) pa[i] = i,cnt[i] = 1,dist[i] = 0; } int findset (int x) { if (x != pa[x]) { int root = findset (pa[x]); dist[x] += dist[pa[x]]; return pa[x] = root; } else return x; } void Unin(int a,int b) { int af = findset (a); int bf = findset (b); pa[bf] = af; dist[bf] = cnt[af]; cnt[af] += cnt[bf]; } int main () { int m,x,y; char op[3]; while (~scanf ("%d",&m)) { Init(); while (m --) { scanf ("%s",op); if (op[0] == 'M') { scanf ("%d%d",&x,&y); Unin(x,y); } else { scanf ("%d",&x); int af = findset (x); printf ("%d\n",cnt[af]-dist[x]-1); } } } return 0; }
相关文章推荐
- POJ 1988 Cube Stacking
- poj 1988 Cube Stacking 并查集的应用
- POJ 1988 Cube Stacking【带权并查集】
- POJ-1988 Cube Stacking
- Cube Stacking(POJ-1988)
- poj 1988 - Cube Stacking(并查集)
- POJ 1988-Cube Stacking
- POJ 1988 Cube Stacking(并查集+路径压缩)
- POJ - 1988 Cube Stacking(带权并查集)
- POJ 1988 Cube Stacking(并查集)
- POJ1988 Cube Stacking
- POJ 1988 Cube Stacking
- POJ 1988 Cube Stacking (并查集)
- POJ 1988 Cube Stacking(并查集+路径压缩)
- poj 1988(并查集)Cube Stacking
- POJ 1988 Cube Stacking(带权并查集)
- POJ - 1988 Cube Stacking
- 【北大夏令营笔记-并查集】poj1988-Cube Stacking
- poj 1988 Cube Stacking(带权并查集)
- POJ 1988 Cube Stacking