UVA 1329 - Corporative Network
带权值的并查集的应用;
代码:
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#define maxn 20005
using namespace std; int f[maxn];
int d[maxn];
int t,n,x,y;
char s[]; int find(int x)
{
if(f[x]!=x)
{
int r=find(f[x]);
d[x]+=d[f[x]];
return f[x]=r;
}
else return x;
} int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=; i<=n; i++){f[i]=i;d[i]=;}
while(scanf("%s",s))
{
if(s[]=='O')break;
if(s[]=='E')
{
scanf("%d",&x);
find(x);
printf("%d\n",d[x]);
}
else if(s[]=='I')
{
scanf("%d%d",&x,&y);
f[x]=y;
d[x]=abs(x-y)%;
}
}
}
return ;
}
UVA 1329 - Corporative Network的更多相关文章
- UVa 1329 - Corporative Network Union Find题解
UVa的题目好多,本题是数据结构的运用,就是Union Find并查集的运用.主要使用路径压缩.甚至不须要合并树了,由于没有反复的连线和改动单亲节点的操作. 郁闷的就是不太熟悉这个Oj系统,竟然使用库 ...
- UVA 1329 Corporative Network【并查集】
题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...
- UVA 3027 Corporative Network 带权并查集、
题意:一个企业要去收购一些公司把,使的每个企业之间互联,刚开始每个公司互相独立 给出n个公司,两种操作 E I:询问I到I它连接点最后一个公司的距离 I I J:将I公司指向J公司,也就是J公司是I公 ...
- UVALive 3027 Corporative Network
---恢复内容开始--- Corporative Network Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld ...
- 【暑假】[实用数据结构]UVAlive 3027 Corporative Network
UVAlive 3027 Corporative Network 题目: Corporative Network Time Limit: 3000MS Memory Limit: 30000K ...
- [LA] 3027 - Corporative Network [并查集]
A very big corporation is developing its corporative network. In the beginning each of the N enterpr ...
- 3027 - Corporative Network(并差集)
3027 - Corporative Network A very big corporation is developing its corporative network. In the begi ...
- LA 3027 Corporative Network 并查集记录点到根的距离
Corporative Network Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu [S ...
- UVALive 3027 Corporative Network 带权并查集
Corporative Network A very big corporation is developing its corporative networ ...
随机推荐
- AHCI vs NVMe
http://www.hkepc.com/13139 儘管現時有不少高階 SSD 產品改用 PCIe 接口,以突破 SATA 接口的頻寬瓶頸,但控制器設計與 SATA 接口 SSD 一樣,採用老舊的 ...
- Linux 内核使用的 GNU C 扩展
gcc核心扩展linuxforum(转)=========================== Linux 内核使用的 GNU C 扩展 =========================== GNC ...
- Qemu下安装Sun Solairs8简明教程 转
http://blog.csdn.net/stonesharp/article/details/8928393 Qemu下安装Sun Solairs8简明教程(Centos6. / Win7) 作者: ...
- hadoop错误org.apache.hadoop.mapred.MapTask$NewOutputCollector@17bda0f2
错误: org.apache.hadoop.mapred.MapTask$NewOutputCollector@17bda0f2 java.io.IOException: Spill failed 错 ...
- android智能天气闹钟应用开发经过
开发这个应用的初衷是这样产生滴,和我一块租房的同学每天早上都是骑单车上班,所以手机闹钟就会定一个刚好适合骑车的起床时间点.但是呢,有一天早上起床以后发现外面下挺大雨,肯定是不能骑车去上班了,于是就只好 ...
- iOS创建界面方法的讨论
以前在入门的时候,找的入门书籍上编写的 demo 都是基于 Storyboards 拖界面的.后来接触公司项目,发现界面都是用纯代码去写复杂的 autoLayout 的.再然后,领导给我发了个 Mas ...
- Android 上使用 iconfont 的一种便捷方案
最近在学习 AIOSO(Alibaba Internal Open Source Organization,即阿里巴巴内部开源组织) 的一个子项目MMCherryUI,这是一个流式布局,可以在运行时做 ...
- Migration of ASP.NET app from IIS6 to IIS7 (7.5)
For many of us familiar problem. You developing applications under IIS6 and you're about to move the ...
- 利用jQuery npoi插件 asxh一般处理文件实现excel的下载
最近开发的过程中遇到这么一个问题,利用ajax和ashx文件实现下载功能.发现代码调试走完之后并没有弹出下载框. 研究了一段时间之后发现解决这种问题有两种方法,1.ajax获取数据集在前台做处理实现导 ...
- grunt 构建工具(build tool)初体验
操作环境:win8 系统,建议使用 git bash (window下的命令行工具) 1,安装node.js 官网下载:https://nodejs.org/ 直接点击install ,会根据你的操 ...