UVA 1329 Corporative Network(并查集)
2016-10-20 21:17
281 查看
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define ss(x) scanf("%d",&x) const int maxn=20000+10; int d[maxn],pa[maxn]; int n; int getroot(int u) { if(pa[u]!=u) { int root=getroot(pa[u]); d[u]+=d[pa[u]]; return pa[u]=root; } else return u; } int main() { int t; ss(t); while(t--) { ss(n); rep(i,1,n) {pa[i]=i;d[i]=0;} char cmd[10]; while(scanf("%s",cmd)&&cmd[0]!='O') { int x,y; if(cmd[0]=='I') { ss(x);ss(y); pa[x]=y; d[x]=abs(x-y)%1000; } if(cmd[0]=='E'){ ss(x); getroot(x); cout<<d[x]<<endl; } } } return 0; }
相关文章推荐
- UVA 1329 - Corporative Network(带权并查集)
- UVA 1329 Corporative Network(并查集:路径压缩)
- LA3027:Corporative Network(并查集) uva 1329
- UVa:1329 Corporative Network(带权并查集)
- 并查集uva1329(LA3027)
- C - Corporative Network UVA - 1329 (并查集)
- Corporative Network UVA - 1329(并查集的修改与查询)
- C - Corporative Network UVA - 1329 -加权并查集
- uva 1329 - Corporative Network(加权并查集)
- UVA - 1329 Corporative Network 合作网络(并查集)
- Corporative Network UVA - 1329 加权并查集
- UVA 1329 Corporative Network【并查集】
- Corporative Network UVA - 1329 加权并查集
- uva 1329 - Corporative Network(数据结构:并查集)
- UVa 1329 Corporative Network(并查集)
- Corporative Network UVA - 1329 加权并查集(压缩路径优化)
- UVA-1329 - Corporative Network(并查集)
- UVa 1329 Corporative Network (加权并查集)
- UVA 1329 Corporative Network【并查集】
- uva1329 Corporative Network(并查集:路径压缩)