LA 3027 Corporative Network
这题感觉和 POJ 1988 Cube Stacking 很像,在路径压缩的同时递归出来的时候跟新distant数组
我发现我一直WA的原因是,命令结束是以字母o结束的,而不是数字0!!
//#define LOCAL
#include <algorithm>
#include <cstdio>
using namespace std; const int maxn = + ;
int parent[maxn], distant[maxn]; int GetParent(int a)
{
if(parent[a] == a) return a;
int root = GetParent(parent[a]);
distant[a] += distant[parent[a]];
return parent[a] = root;
} int main(void)
{
#ifdef LOCAL
freopen("3027in.txt", "r", stdin);
#endif int T, n;
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
char cmd[];
for(int i = ; i <= n; ++i)
{
parent[i] = i;
distant[i] = ;
}
while(scanf("%s", cmd) && cmd[] != 'O')
{
int a, b;
if(cmd[] == 'E')
{
scanf("%d", &a);
GetParent(a);
printf("%d\n", distant[a]);
}
else
{
scanf("%d%d", &a, &b);
parent[a] = b;
distant[a] = abs(a - b) % ;
}
}
}
return ;
}
代码君
LA 3027 Corporative Network的更多相关文章
- [LA] 3027 - Corporative Network [并查集]
A very big corporation is developing its corporative network. In the beginning each of the N enterpr ...
- LA 3027 Corporative Network 并查集记录点到根的距离
Corporative Network Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu [S ...
- 并查集(路径更新) LA 3027 Corporative Network
题目传送门 题意:训练指南P192 分析:主要就是一个在路径压缩的过程中,更新点i到根的距离 #include <bits/stdc++.h> using namespace std; c ...
- 【LA 3027 Corporative Network】
·一些很可爱的询问和修改,放松地去用并查集解决. ·英文题,述大意: 输入n(5<=n<=20000)表示树有n个节点,并且会EOF结束地读入不超过 20000个操作,一共有两种: ...
- 【暑假】[实用数据结构]UVAlive 3027 Corporative Network
UVAlive 3027 Corporative Network 题目: Corporative Network Time Limit: 3000MS Memory Limit: 30000K ...
- 3027 - Corporative Network(并差集)
3027 - Corporative Network A very big corporation is developing its corporative network. In the begi ...
- 3027 - Corporative Network
3027 - Corporative Network 思路:并查集: cost记录当前点到根节点的距离,每次合并时路径压缩将cost更新. 1 #include<stdio.h> 2 #i ...
- UVALive 3027 Corporative Network
---恢复内容开始--- Corporative Network Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld ...
- UVALive 3027 Corporative Network 带权并查集
Corporative Network A very big corporation is developing its corporative networ ...
随机推荐
- Red hat Linux 安装Node.js 源码安装
1. 下载源码包 http://nodejs.org/dist/v0.10.29/node-v0.10.29.tar.gz 2.准备安装环境,>python2.6, gcc, g++ pytho ...
- mysql 数据库优化
提到优化,先要确定出现的问题,是存储引擎选择问题,还是sql语句使用问题(如:索引)亦或者是单一存储服务器对于千万级别的数据力不从心. 解决方法:1.根据不同业务选用不同存储引擎,虽然一般情况下都优先 ...
- mysql去除重复查询的SQL语句基本思路
SELECT R.* FROM trans_flow R, (SELECT order_no, MAX(status_time) AS status_time FROM trans_flow GROU ...
- POJ 2533 Longest Ordered Subsequence
题目描述:LIS(Longest Increasing Subsequence)模板题 分析:O(n^2)的方法 状态表示:d[i]表示以i结尾的最长上升子序列长度 转移方程:d[i]=max{ 1, ...
- 刘汝佳 算法竞赛-入门经典 第二部分 算法篇 第五章 2(Big Number)
这里的高精度都是要去掉前导0的, 第一题:424 - Integer Inquiry UVA:http://uva.onlinejudge.org/index.php?option=com_onlin ...
- WPF、Windows Forms和Silverlight间的联系和区别(转)
WPF.Windows Forms和Silverlight间的联系和区别http://blog.csdn.net/bitfan/article/details/6128391 .NET Windows ...
- java控制反转与依赖注入
1.简介 依赖注入和控制反转,目的是为了使类与类之间解耦合,提高系统的可扩展性和可维护性,下面通过一个例子来引入这一概念. 2.案例 1)一般情况下的类耦合 Main.java public clas ...
- shell脚本替换文件中字符
1.将当前目录下包含jack串的文件中,jack字符串替换为tom sed -i "s/jack/tom/g" `grep "jack" -rl ./` 2.将 ...
- 浏览器的CSS各种hack,大汇总
对着IE久了也有感觉了,在win10出新浏览器以及中国的IE6+用户没有普及新的浏览器前IE还是个坑,所以hack这东西还是要掌握一点的.不废话直接贴图 记得之前在项目里面针对IE6的hack是这样写 ...
- Linux下配置JDK与Tomcat
一.下载安装对应的jdk,并配置Java环境. 官网下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u26-down ...