poj Corporative Network
来源:互联网 发布:手机淘宝下载安装2016 编辑:程序博客网 时间:2024/04/28 00:57
题目链接:http://poj.org/problem?id=1962
题目思路:并查集。
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<string>#include<queue>#include<math.h>#include<algorithm>#include<vector>#include<stack>#include<list>#include<iostream>#include<map>using namespace std;#define inf 0x3f3f3f3f#define Max 110int max(int a,int b){return a>b?a:b;}int min(int a,int b){return a<b?a:b;}int father[20100],val[20100],n,t;inline void init(){ int i; for(i=0;i<=n;i++) father[i]=i,val[i]=0;}inline int find(int x){ int tmp; if(x!=father[x]) { tmp=father[x]; father[x]=find(father[x]); val[x]=val[tmp]+val[x]; } return father[x];}int main(){ int i,x,y; char op[2]; scanf("%d",&t); while(t--) { scanf("%d",&n); init(); while(scanf("%s",op)!=EOF) { if(op[0]=='O') break; if(op[0]=='E') { scanf("%d",&x); find(x); printf("%d\n",val[x]); } else { scanf("%d%d",&x,&y); father[x]=y; val[x]+=abs(x-y)%1000; } } } return 0;}
- poj Corporative Network
- poj 1962 Corporative Network
- POJ-1962-Corporative Network
- poj 1963 Corporative Network
- POJ 1962 Corporative Network
- POJ-1962 Corporative Network
- POJ 1962 Corporative Network
- POJ 1962-Corporative Network
- poj 1962 Corporative Network
- POJ 1962 Corporative Network
- 【35.86%】【POJ 1962】Corporative Network
- 并查集 Corporative Network POJ 1962
- Corporative Network
- Corporative Network
- Corporative Network
- Corporative Network
- poj 1962 Corporative Network 并查集的应用
- poj 1962 Corporative Network 带权并茶集
- 杭电1004代码
- LinkedHashMap特性 按插入和访问顺序排序
- C++:STL标准入门汇总
- 五年
- SQL SERVER 日期函数
- poj Corporative Network
- 正极峰值检测器
- 今日免费PNG图标集下载 - SweetiePlus
- JQuery判断radio是否选中,获取选中值
- POJ 3189 图论技巧题
- gtk编程Hello World
- ListView 下拉刷新错误
- 负极峰值检测器
- POJ 2457 Part Acquisition(最短路)