带权值的并查集的应用;

代码:

 #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的更多相关文章

  1. UVa 1329 - Corporative Network Union Find题解

    UVa的题目好多,本题是数据结构的运用,就是Union Find并查集的运用.主要使用路径压缩.甚至不须要合并树了,由于没有反复的连线和改动单亲节点的操作. 郁闷的就是不太熟悉这个Oj系统,竟然使用库 ...

  2. UVA 1329 Corporative Network【并查集】

    题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...

  3. UVA 3027 Corporative Network 带权并查集、

    题意:一个企业要去收购一些公司把,使的每个企业之间互联,刚开始每个公司互相独立 给出n个公司,两种操作 E I:询问I到I它连接点最后一个公司的距离 I I J:将I公司指向J公司,也就是J公司是I公 ...

  4. UVALive 3027 Corporative Network

    ---恢复内容开始--- Corporative Network Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld ...

  5. 【暑假】[实用数据结构]UVAlive 3027 Corporative Network

    UVAlive 3027 Corporative Network 题目:   Corporative Network Time Limit: 3000MS   Memory Limit: 30000K ...

  6. [LA] 3027 - Corporative Network [并查集]

    A very big corporation is developing its corporative network. In the beginning each of the N enterpr ...

  7. 3027 - Corporative Network(并差集)

    3027 - Corporative Network A very big corporation is developing its corporative network. In the begi ...

  8. LA 3027 Corporative Network 并查集记录点到根的距离

    Corporative Network Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu [S ...

  9. UVALive 3027 Corporative Network 带权并查集

                         Corporative Network A very big corporation is developing its corporative networ ...

随机推荐

  1. StirngUtil工具类 之 邮箱注冊 域名不区分大写和小写方法

    /** * 传入邮箱域名所有变为小写,然后拼接前缀返回 *<b>Summary: </b> * emailDomainTransform() * @param domain * ...

  2. 底部菜单栏(三)Fragment+FragmentTabHost实现仿新浪微博底部菜单栏

    一.实现效果图 二.项目工程结构 三.详细代码编写 1.主tab布局界面,main_tab_layout: 双击代码全选 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...

  3. Linux shell的&&和||--转载

    Linux shell的&&和||   shell 在执行某个命令的时候,会返回一个返回值,该返回值保存在 shell 变量 $? 中.当 $? == 0 时,表示执行成功:当 $? ...

  4. 从源码角度理解android动画Interpolator类的使用

    做过android动画的人对Interpolator应该不会陌生,这个类主要是用来控制android动画的执行速率,一般情况下,如果我们不设置,动画都不是匀速执行的,系统默认是先加速后减速这样一种动画 ...

  5. VC++文件相关操作的函数封装实现

    在开发编译工具中,需要用到文件的相关操作,于是就封装了相关的函数实现: //判断文件是否存在 BOOL FileIsExist(CString strFileName) { CFileFind fin ...

  6. Ubuntu 13.10 Rhythmbox 播放器不能播放MP3。安装插件

    Ctrl+Alt+T > sudo apt-get install ubuntu-restricted-extras 因为版权和专利的问题,MP3等一些non-free的格式文件支持没有出现在免 ...

  7. oracle知识杂记

    索引类型 1.B-树索引 分区索引.压缩索引.函数索引等都属于B-树索引 2.位图索引 3.索引组织表 索引管理 1.普通单列索引                    对where条件.group ...

  8. 多线程(Thread),其实很简单!

    目录:  1:线程简介 2:怎么操作线程      3:Thread的常用方法 4:简单的获奖机     5:应用程序域   线程:是Windows任务调度的最小单位.线程是程序中的一个执行流,每个线 ...

  9. Linux - 引用

    双引号 如果把文本放在双引号中,那么 shell 使用的所有特殊字符都将失去它们的特殊含义,而被看成普通字符.字符 "$"(美元符号)."\"(反斜杠).&qu ...

  10. C#一些小技巧(二)

    教你们怎么改配色方案,因为本人智障了很久,每次想改颜色的时候都会看到一大圈的选项,难以琢磨,但是智障了那么久终于被我找到了所有的关联. 首先,要告诉你们的是,其实C#里面要改的东西只有那么几个,但是注 ...