这题感觉和 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的更多相关文章

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

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

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

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

  3. 并查集(路径更新) LA 3027 Corporative Network

    题目传送门 题意:训练指南P192 分析:主要就是一个在路径压缩的过程中,更新点i到根的距离 #include <bits/stdc++.h> using namespace std; c ...

  4. 【LA 3027 Corporative Network】

    ·一些很可爱的询问和修改,放松地去用并查集解决. ·英文题,述大意: 输入n(5<=n<=20000)表示树有n个节点,并且会EOF结束地读入不超过 20000个操作,一共有两种:    ...

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

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

  6. 3027 - Corporative Network(并差集)

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

  7. 3027 - Corporative Network

    3027 - Corporative Network 思路:并查集: cost记录当前点到根节点的距离,每次合并时路径压缩将cost更新. 1 #include<stdio.h> 2 #i ...

  8. UVALive 3027 Corporative Network

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

  9. UVALive 3027 Corporative Network 带权并查集

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

随机推荐

  1. eclipse 自动 注释

    在使用Eclipse 编写Java代码时,自动生成的注释信息都是按照预先设置好的格式生成的. 修改作者.日期注释格式:打开Windows->Preferences->Java->Co ...

  2. javascript设计模式-迭代器模式(Iterator)

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. 由浅入深了解Thrift之服务模型和序列化机制

    一.Thrift介绍 Thrift是一个软件框架,用来进行可扩展且跨语言的服务的开发.它结合了功能强大的软件堆栈和代码生成引擎.其允许你定义一个简单的定义文件中的数据类型和服务接口.以作为输入文件,编 ...

  4. HDU 4632 Palindrome subsequence(区间dp,回文串,字符处理)

    题目 参考自博客:http://blog.csdn.net/u011498819/article/details/38356675 题意:查找这样的子回文字符串(未必连续,但是有从左向右的顺序)个数. ...

  5. linux kill命令详解

    1.命令格式: kill[参数][进程号] 2.命令功能: 发送指定的信号到相应进程.不指定型号将发送SIGTERM(15)终止指定进程.如果任无法终止该程序可用“-KILL” 参数,其发送的信号为S ...

  6. Hadoop InputFormat OutputFormat

    InputFormat有两个抽象方法: getSplits     createRecordReader   InputSplits 将数据按照Split进行切分,一个Split分给一个task执行. ...

  7. servlet学习笔记四

    Servlet 主要内容: 1)servlet初始化参数与上下文参数 2)过滤器 3)监听器一.servlet初始化参数与上下文参数 1)servlet初始化参数 把某些变量放在web.xml配置,到 ...

  8. netbeans使用

    下载地址 https://netbeans.org/downloads/ https://netbeans.org/downloads/start.html?platform=linux&la ...

  9. win7 安装Redis

    1.下载Redis的压缩包 https://github.com/dmajkic/redis/downloads 我下载的是redis-2.4.5-win32-win64.zip 下载完后将其解压放在 ...

  10. android-exploitme(五):不安全的数据存储

    今天我来看看如果android将数据存储在sdcard,它的权限是什么样的 1. 打开emm软件,做一笔转账.