【HDU】2818-Building Block(并查集)
来源:互联网 发布:软件开发过程不包括 编辑:程序博客网 时间:2024/06/14 04:34
坑死了,这道题QAQ。。。说好的没有0,但是后台数据有0,WA了一下午= =
利用num[i]代表i下面有几个格子,Size[i]代表i做底的时候这一堆有几个箱子
#include<cstdio>#include<algorithm>using namespace std;const int maxn = 30005;int n,fa[maxn];int num[maxn],Size[maxn];char op[5];int find_father(int u){ if(fa[u] == u) return fa[u]; else{ int temp = fa[u]; fa[u] = find_father(fa[u]); num[u] += num[temp]; return fa[u]; }}int main(){ while(scanf("%d",&n) != EOF){ for(int i = 0; i <= 30000; i++){ fa[i] = i; Size[i] = 1; num[i] = 0; } int x,y; for(int i = 1; i <= n; i++){ scanf("%s",op); if(op[0] == 'M'){ scanf("%d%d",&x,&y); int fx = find_father(x),fy = find_father(y); if(fx!= fy){ fa[fx] = fy; num[fx] = Size[fy]; Size[fy]+= Size[fx]; Size[fx] = 0; } } else{ scanf("%d",&x); find_father(x); printf("%d\n",num[x]); } } } return 0;}
0 0
- HDU 2818 Building Block(并查集)
- hdu 2818 Building Block(并查集)
- HDU 2818 Building Block (并查集)
- hdu 2818 Building Block(并查集)
- hdu 2818 Building Block (并查集)
- HDU 2818 Building Block(带权并查集)
- HDU 2818 Building Block(带权并查集)
- 【HDU】2818-Building Block(并查集)
- HDU 2818 Building Block(带权并查集)
- HDU 2818 Building Block (带权并查集)
- hdu 2818 Building Block 并查集 路径压缩
- Hdu 2818 Building Block 加权并查集
- HDU 2818 Building Block 带权并查集
- hdu 2818 Building Block(带权并查集)
- hdu 2818 Building Block(加权并查集)
- HDU 2818 Building Block 带权并查集
- hdu 2818 Building Block【基础带权并查集】
- hdu 2818 Building Block(带权并查集)
- hdu5254水题小暴力
- 从语言进步到编程
- XMPP协议及其扩展详解
- java 日期计算工具类小结
- Linux 内核内存泄露工具使用
- 【HDU】2818-Building Block(并查集)
- 有关按钮的触摸优先级和layer的触摸事件冲突问题
- iOS应用架构谈 网络层设计方案
- IP地址和端口号详细解析
- Longest Common Prefix
- GO语言学习: 项目构建 及编译 初步
- K中心点算法(K-medoids) java实现
- Android异步批量下载图片并缓存
- 通过java的反射机制实现Map、JavaBean、JSON的相互转换工具类