题目有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. [转]Oracle connection strings

    本文转自:http://www.connectionstrings.com/oracle/ Standard Data Source=MyOracleDB;Integrated Security=ye ...

  2. [转]Insert, Update, and Delete Destination table with SSIS

    本文转自:http://www.rad.pasfu.com/index.php?/archives/150-Insert,-Update,-and-Delete-Destination-table-w ...

  3. RMAN冗余备份概念与方法

    冗余备份概念 RMAN提供了一种更谨慎的备份策略:duplexed方式备份,其实质就是在生成备份集的同时,向指定位置copy指定份数(最大不超过4)的备份集复制,以避免在灾难性事故时数据库损坏和备份丢 ...

  4. gdc skin

    https://www.gdcvault.com/play/1024410/Achieving-High-Quality-Low-Cost 这篇是教美术怎么用做地形那种方法 复用贴图 做skin的 做 ...

  5. c/c++的|、||、&、&&、异或、~、!运算

    位运算     位运算的运算分量只能是整型或字符型数据,位运算把运算对象看作是由二进位组成的位串信息,按位完成指定的运算,得到位串信息的结果. 位运算符有:     &(按位与).|(按位或) ...

  6. NHibernate中几个集合的选择

    NHibernate是从Hibernate移植过来的基于NET平台的一个ORM框架,同时跟这框架一起的还有一个开源库,叫做Iesi.Collections,这个库扩展了NET平台下面的几个集合,所谓集 ...

  7. [HTML5] Track First Contentful Paint with PerformanceObserver and Google Analytics

    "If you can't measure it, you can't improve it." The first step when doing performance wor ...

  8. 利用Referer请求头阻止"盗链"

    转自:http://wisdomsong2007.blog.163.com/blog/static/47783725200882523820664/ 前言 有一些站点自己没有提供下载空间,但是为了吸引 ...

  9. Android 事件分发

    引言 项目中涉及到的触摸事件分发较多,例如:歌词模式下,上下滑动滚动歌词,左右滑动切换歌曲.此时,理解事件分发机制显得尤为重要 , 既要保证下方的ViewPager能接收到,又要确保上层View能响应 ...

  10. Unity 3d导入3dMax模型 产生若干问题

    Unity 3d导入3dMax模型 会产生若干问题,按照官方 的说明,将max 模型导成fbx文件 导入untiy似乎也不能解决 1.x轴向偏转3dmax模型导入后自动有一个x轴270度的偏转,巧合的 ...