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 ...
随机推荐
- linux解压缩命令
1.tar -cvf /data/sc2.tar /data (只打包,不压缩) 把/data下的文件打包成 sc.tar 上面两个都是绝对路径噢 tar -zcvf /data/sc2.tar.g ...
- oracle修改登录认证方式
通过配置sqlnet.ora文件,我们可以修改oracle登录认证方式. SQLNET.AUTHENTICATION_SERVICES=(NTS);基于操作系统的认证 SQLNET.AUTHENTIC ...
- RedHat7搭建MongoDB
yum安装MongoDB 添加MongoDB源# vi /etc/yum.repos.d/mongodb-org-3.0.repo [mongodb-org-3.0] name=MongoDB Rep ...
- php 计算一个字符串在另一个字符串中出现的次数
<?php $text = 'This is a test'; echo strlen($text); // 14 echo substr_count($text, 'is'); // 2 // ...
- Log4net 集成到MVC+EF框架
前提引用Log4Net.dll文件 1. [assembly: log4net.Config.XmlConfigurator(ConfigFile = "Web.config", ...
- iOS 地图坐标系之间的转换WGS-84世界标准坐标、GCJ-02中国国测局(火星坐标,高德地图)、BD-09百度坐标系转换
开发过程中遇到地图定位不准确,存在偏差.首先确认你获取到的坐标所在坐标系跟地图数据是不是相匹配的. 常用的地图SDK:高德地图使用的是GCJ-02(也就是火星坐标系),百度使用的是BD-09百度坐标系 ...
- iOS 开发工具
Github 社区 https://github.com/ iOS 开发类库 http://www.code4app.com/thread-7831-1-1.html (出处: Code4App-iO ...
- OC调用Swift 整理步骤!总结别人的!方便自己查找!
1. 2. 上面的修改了一个配置项,有一个Product Module Name在后面会使用. 在工程里面点击File/New/File…,选择iOS/Source/Cocoa Touch Class ...
- C#删除数组元素代码
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...
- ES6学习笔记之Promise
入职百度EFE团队实习已经三周了,实习中接触到了生产环境的技术和开发流程,大开眼界,和自己在学校接小作坊式项目是很不一样的体验.其中一个很大的感触是,ES6早已不是“选修”的尝鲜技术,而是已经全面普及 ...