poj1962 Corporative Network
来源:互联网 发布:unity3d旧版动画系统 编辑:程序博客网 时间:2024/04/29 01:58
题意:
14E 3I 3 1E 3I 1 2E 3I 2 4E 3O意为一共1个样例,第一个样例有4个点,编号1,2,3,4
E 3的意思是求3到根结点的距离,显然为0
I 3 1的意思是将3(一定是根节点)所在并查集加入到1所在并查集中,3节点到1点的距离为(3-1)%1000
解法:
并查集
代码:
#include<cstdio>#include<iostream>#include<algorithm>using namespace std;class T{public:int parent[20010];//父亲节点int len[20010];//到其父节点的距离void init(int n){for(int i=1;i<=n;i++){parent[i]=i;}}int root(int x){if(parent[x]==x){len[x]=0;return x;}int rx=root(parent[x]);len[x]+=len[parent[x]];parent[x]=rx;return rx;}void Merge(int a,int b)//a是根节点,连接到b所在的集合里{ int rb=root(b);parent[a]=rb;len[a]=len[b]+abs(a-b)%1000;}}disjoinset;//我的并查集int main(){int total;scanf("%d",&total);while(total--){int n;scanf("%d",&n);disjoinset.init(n);char type;while(cin>>type,type!='O'){if(type=='E'){int t;scanf("%d",&t);disjoinset.root(t);printf("%d\n",disjoinset.len[t]);}else{int a,b;scanf("%d%d",&a,&b);disjoinset.Merge(a,b);}}}return 0;}
- POJ1962 Corporative Network
- poj1962 Corporative Network
- 【poj1962】 Corporative Network
- Corporative Network(POJ1962)(B)
- POJ1962、uva3027 Corporative Network
- POJ1962 Corporative Network 并查集
- POJ1962 - Corporative Network - 并查集
- POJ1962:Corporative Network(并查集)
- poj1962 Corporative Network(带权并查集)
- Corporative Network
- Corporative Network
- Corporative Network
- Corporative Network
- poj Corporative Network
- poj 1962 Corporative Network
- LA - 3027 - Corporative Network
- LA--3027--Corporative Network
- POJ-1962-Corporative Network
- android开发前言
- oracle用localhost连接数据库能连上,用ip连接不上
- java从网上获取ipv4的地址信息
- 靠,一天又没了
- 如何使用ArrayList类实现n位数的任意组合?也考虑0在首位的情况
- poj1962 Corporative Network
- MS SQL Server查询优化方法
- 南开 2216: Boring Game (排序)
- hdu4360
- 制作根文件系统树
- 双目视觉中一些启发性的话(一)
- HDU 1158 Employment Planning
- Android开发详解之onTouch和onClick详解
- HDU 1198 Farm Irrigation