题目有2种操作, 一种是查询,一种是设置。

设置为将u的父亲设置为v,然后他们之间的距离为|u-v|%1000

查询为该点到根点的距离

用并查集做,做的时候注意维护即可,注意取余操作。

代码:

 #include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const int N = ;
int d[N],F[N];
int init(int x)
{
for(int i =;i<=x;i++)
{
F[i] = i;
d[i]=;
}
}
int findset(int x)
{
if(F[x]!=x)
{
int root = findset(F[x]);
d[x] = d[x]+d[F[x]];
return F[x] = root;
}
else return x;
}
int main()
{
int T,n;
char s[];
scanf("%d",&T);
while(T--)
{
int n,u,v;
scanf("%d",&n);
init(n);
while(scanf("%s",s) && s[]!='O')
{
if(s[] == 'E')
{
scanf("%d",&u);
findset(u);
printf("%d\n",d[u]);
}
else
{
scanf("%d%d",&u,&v);
F[u] = v;
d[u] = abs(u-v)%;
}
}
}
return ;
}

POJ 1962-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. POJ 2236 Wireless Network (并查集)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 18066   Accepted: 761 ...

  4. poj 2236 Wireless Network (并查集)

    链接:http://poj.org/problem?id=2236 题意: 有一个计算机网络,n台计算机全部坏了,给你两种操作: 1.O x 修复第x台计算机 2.S x,y 判断两台计算机是否联通 ...

  5. poj 1962 Corporative Network

    主题链接:http://poj.org/problem?id=1962 思路:每一个集合中用根节点标记这个集合,每一个点到根节点的距离. code: <span style="font ...

  6. POJ 2236 Wireless Network [并查集+几何坐标 ]

    An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...

  7. UVALive - 3027 Corporative Network (并查集)

    这题比较简单,注意路径压缩即可. AC代码 //#define LOCAL #include <stdio.h> #include <algorithm> using name ...

  8. Network POJ - 3694(lca并查集+连通图求桥)

    就是求出原先图中的桥的数量,在每一次询问时加入一条新边,求加入当前边后图中剩余的桥的数量 求出原先图中的桥的数量,然后减去新加入边的两端点之间的桥的数量,就是剩余桥的数量.. 用并查集把属于同一集合的 ...

  9. Corporative Network_并查集

    Description A very big corporation is developing its corporative network. In the beginning each of t ...

  10. poj 1733(带权并查集+离散化)

    题目链接:http://poj.org/problem?id=1733 思路:这题一看就想到要用并查集做了,不过一看数据这么大,感觉有点棘手,其实,我们仔细一想可以发现,我们需要记录的是出现过的节点到 ...

随机推荐

  1. [转]Using the Microsoft Connector for Oracle by Attunity with SQL Server 2008 Integration Services

    本文转自:http://technet.microsoft.com/en-us/library/ee470675(v=sql.100).aspx SQL Server Technical Articl ...

  2. Wishbone总线从接口转Xilinx MIG (Spartan 6)

    //*************************************************************************** // Copyright(c)2016, L ...

  3. Java笔记8:Hibernate连接Oracle

    1下载hibernate-3.6.0 Final.zip到任意目录,解压缩后得到hibernate目录 2下载slf4j-1.7.13.zip到任意目录,解压缩后得到slf4j-1.7.13 3操作数 ...

  4. 【java】Could not find or load main class

    https://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean A comm ...

  5. Spring结合AspectJ的研究

    本文阐述以下内容:1.AspectJ是什么及使用方式2.Spring AOP和AspectJ的区别3.Spring结合AspectJ的使用方法和原理4.Spring注解方式使用AspectJ遇到的问题 ...

  6. [Functional Programming Monad] Combine Stateful Computations Using A State Monad

    The true power of the State ADT really shows when we start combining our discrete, stateful transact ...

  7. C#时间的味道——任时光匆匆我只在乎你

    如果没有遇见你,我将会是在哪里?日子过的怎么样人生是否要珍惜...任时光匆匆我只在乎你,心甘情愿感染你的气息,人生几何能得到知己...一首邓丽君的<我只在乎你>不禁令我唏嘘不已,这些年离我 ...

  8. .Net Framework 之 托管代码和非托管代码的区别

    一.什么是托管代码(managed code)? 托管代码:是微软的中间语言(IL),即微软中间语言MSIL(Microsoft Interspace Language). “ 源代码→机器码 ”运行 ...

  9. android 实现调查问卷-单选-多选

    非常久没写东西了.今天来总结下有关android调查问卷的需求实现. 转载请加地址:http://blog.csdn.net/jing110fei/article/details/46618229 先 ...

  10. 复制VirtualBox中的虚拟机

    假设简单的复制虚拟机是行不通的.复制过程须要一个小技巧,复制出来的VDI文件无法在虚拟介质管理器中注冊.由于每一个VDI文件都有一个唯一的uuid.而VirtualBox不同意注冊反复的uuid. 为 ...