POJ1988 Cube Stacking
来源:互联网 发布:淘宝店铺收藏的链接 编辑:程序博客网 时间:2024/06/07 10:27
/*并查集*/#include <iostream>#include <string>using namespace std;const int MAXN = 30005;int father[MAXN], Rank[MAXN], up[MAXN];int p;void init(){for (int i = 0; i < MAXN; ++i) {father[i] = i;Rank[i] = 1;up[i] = 0;}}int getfather(int x){int num;if (father[x] != x) {num = father[x];father[x] = getfather(father[x]);up[x] += up[num];}return father[x];}void merge(int x, int y){int a = getfather(x);int b = getfather(y);father[b] = a;up[b] = Rank[a];Rank[a] += Rank[b];}int main(){while (cin >> p) {init();int x, y, z;string s;for (int k = 0; k < p; ++k) {cin >> s;if (s == "M") {cin >> x >> y;merge(x, y);}else if (s == "C") {cin >> z;int tmp = getfather(z);cout << Rank[tmp] - up[z] - 1 << endl;}}}return 0;}
0 0
- POJ1988 Cube Stacking
- POJ1988 Cube Stacking
- poj1988 Cube Stacking
- poj1988 cube stacking
- POJ1988 Cube Stacking
- POJ1988 Cube Stacking
- POJ1988-Cube Stacking
- POJ1988 Cube Stacking
- POJ1988——Cube Stacking
- POJ1988 Cube Stacking [并查集]
- POJ1988 - Cube Stacking - 并查集
- poj1988 Cube Stacking 并查集
- 【POJ1988】Cube Stacking(并查集)
- POJ1988 Cube Stacking(并查集)
- POJ1988 Cube Stacking(并查集)
- POJ1988:Cube Stacking(并查集)
- POJ1988--cube stacking(2007-04-18 17:01)
- 【北大夏令营笔记-并查集】poj1988-Cube Stacking
- 105 九的余数
- 新生排位赛第五场 矩阵快速幂
- 106 背包问题
- twisted日志源码分析
- CoreText.framework --- 段落样子CTParagraphStyle
- POJ1988 Cube Stacking
- 小白入门笔记——网站路径server.mappath()
- hdu 1431 素数回文
- CoreText.framework --- 图文混排
- 108 士兵杀敌(一)
- 虚拟地址转换为物理地址
- -g、-ggdb、-g3和-ggdb3之间的区别
- 大概是个好撒噶哈撒撒看见大家撒看见
- 发达省市地方好撒地方独守空房颠三倒四疯狂的发生口角