题目有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. iOS:UIResponser控件的介绍(响应者)

    UIResponser响应者控件   知识: 在iOS中不是任何对象都能处理事件,只有继承了UIResponser的对象才能接收并处理事件.我们称之为“响应者对象” UIApplication,UIV ...

  2. Delphi 资源文件( .res)

    一.    现在的Windows应用程序几乎都使用图标.图片.光标.声音等,我们称它们为资源(Resource).最简单的使用资源的办法是把这些资源的源文件打入软件包,以方便程序需要的时候调用.资源是 ...

  3. 利用Nodejs & Cheerio & Request抓取Lofter美女图片

    还是参考了这篇文章: http://cnodejs.org/topic/54bdaac4514ea9146862abee 另外有上面文章 nodejs抓取网易公开课的一些经验. 代码如下,注意其中用到 ...

  4. 一个手绘normal的方法

    https://polycount.com/discussion/98983/how-to-paint-flow-anisotropic-comb-maps-in-photoshop flow map ...

  5. phpcms v9 wap手机门户站点内容页添加上一篇、下一篇的方法

    PHP源码修改:打开 phpcms\modules\wap\index.php 文件找到if(!$r || $r['status'] != 99) showmessage(L('info_does_n ...

  6. weblogic8.1 登陆5 ip 限制

    weblogic8.1  5 ip 限制 报错信息如图所示: 解决办法:此weblogic 未破解,去网上下载破解包,然后放到 copy weblogic_sp.jar to $WL_HOME/ser ...

  7. netmap -- ixgbe

    利用netmap抓ixgbe网卡上的以太网帧,跟e1000e网卡有区别. 使用e1000.e1000e网卡发以太网帧只要以太网帧的格式正确就可以了.只要格式和 目的MAC.源MAC地址正确,网卡就可以 ...

  8. [React] Detect user activity with a custom useIdle React Hook

    If the user hasn't used your application for a few minutes, you may want to log them out of the appl ...

  9. LeetCode Add Binary |My Solution

    Given two binary strings, return their sum (also a binary string). For example, a = "11" b ...

  10. DataBase 之 拉链表结构设计

    一.概念 拉链表是针对数据仓库设计中表存储数据的方式而定义的,顾名思义,所谓拉链,就是记录历史.记录一个事物从开始,一直到当前状态的所有变化的信息. 在历史表中对客户的一生的记录可能就这样几条记录,避 ...