这题感觉和 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. static_cast和reinterpret_cast

    static_cast和reinterpret_cast 相同点:都是暴力转换,从一个类型转换为另一个类型,对于类指针不会保证安全性   static_cast和reinterpret_cast的区别 ...

  2. java基础类:Object类和Math类

    1.2.3.4.5.6.7.7.

  3. 【三】php之梗

    1.php没有顶级作用域,所以你没办法在函数内部使用变量(参数传递除外,而且常量是可以的哟),所以你的变量即使是static的也不能在函数外声明函数里用.除非借助global关键字修饰变量才可以.但是 ...

  4. HDU 1715 大菲波数(JAVA, 简单题,大数)

    题目 //BigInteger 和 BigDecimal 是在java.math包中已有的类,前者表示整数,后者表示浮点数 import java.io.*; import java.util.*; ...

  5. Difference Between Vector and Deque in C++

    1) Dequeue can quickly insert or delete both at the front or the end. However, vector can only quick ...

  6. 数据库链接 mysql,sqlserver

    1.生成对象工厂 /// <summary> /// 生成对象工厂 /// </summary> public class DBFactory { /// <summar ...

  7. Struts2 Convention插件的使用(4)使用@Action注解返回json数据

    package com.hyy.action; import java.util.HashMap; import java.util.Map; import org.apache.struts2.co ...

  8. Eclipse Java EE 编译器设置JSP默认编码

    在windows-preferences-web-jsp files-encoding那里设置默认编码.如下图所示:

  9. tomcat简介及原理解说

    Tomcat简介 作者:杨晓(http://blog.sina.com.cn/u/1237288325) 目录: ----Tomcat背景 ----Tomcat目录 ----Tomcat类加载 --- ...

  10. Axis2学习的第一天

    按照下面,分别建2个工程,一个client(客户端),一个server(服务端) 先实现服务端: 1.编写services.xml文件,该文件是放在aar文件里的\META-INF目录下的: < ...