Wireless Network
Time Limit: 10000MS   Memory Limit: 65536K
Total Submissions: 16832   Accepted: 7068

Description

An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the network were all broken. The computers are repaired one by
one, and the network gradually began to work again. Because of the hardware restricts, each computer can only directly communicate with the computers that are not farther than d meters from it. But every computer can be regarded as the intermediary of the
communication between two other computers, that is to say computer A and computer B can communicate if computer A and computer B can communicate directly or there is a computer C that can communicate with both A and B. 



In the process of repairing the network, workers can take two kinds of operations at every moment, repairing a computer, or testing if two computers can communicate. Your job is to answer all the testing operations. 

Input

The first line contains two integers N and d (1 <= N <= 1001, 0 <= d <= 20000). Here N is the number of computers, which are numbered from 1 to N, and D is the maximum distance two computers can communicate directly. In the next N lines, each contains two integers
xi, yi (0 <= xi, yi <= 10000), which is the coordinate of N computers. From the (N+1)-th line to the end of input, there are operations, which are carried out one by one. Each line contains an operation in one of following two formats: 

1. "O p" (1 <= p <= N), which means repairing computer p. 

2. "S p q" (1 <= p, q <= N), which means testing whether computer p and q can communicate. 



The input will not exceed 300000 lines. 

Output

For each Testing operation, print "SUCCESS" if the two computers can communicate, or "FAIL" if not.

Sample Input

4 1
0 1
0 2
0 3
0 4
O 1
O 2
O 4
S 1 4
O 3
S 1 4

Sample Output

FAIL
SUCCESS

注意要区分修过的和没修过的

代码:

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
#define M 1005
#define LL __int64 struct node{
int x, y;
}s[M];
int map[M][M], fat[M], vis[M]; int f(int x){
if(fat[x] != x) fat[x] = f(fat[x]);
return fat[x];
} int main(){
int n, d;
scanf("%d%d", &n, &d);
int i, j;
d*=d;
for(i = 1; i <= n; i ++){
scanf("%d%d", &s[i].x, &s[i].y);
map[i][i] = 0;
for(j = i-1; j> 0; j --){
map[j][i] = map[i][j] = (s[i].x-s[j].x)*(s[i].x-s[j].x)+(s[i].y-s[j].y)*(s[i].y-s[j].y);
// printf("%d..map(%d, %d)\n", map[i][j], i, j);
}
}
char ss[2];
int a, b;
memset(vis, 0, sizeof(vis));
for(i = 1; i <= n; i++) fat[i] = i;
while(scanf("%s", ss) == 1){
if(ss[0] == 'O'){
scanf("%d", &a);
vis[a] = 1;
for(i = 1; i <= n; i ++){
if(vis[i]&&map[a][i] <= d&&i != a){
int x = f(a); int y = f(i);
if(x != y) fat[x] = y;
}
}
}
else{
scanf("%d%d", &a, &b);
int x = f(a); int y = f(b);
if(vis[a]&&vis[b]&&x == y) printf("SUCCESS\n");
else printf("FAIL\n");
}
}
return 0;
}

poj 2236 Wireless Network 【并查集】的更多相关文章

  1. POJ 2236 Wireless Network (并查集)

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

  2. poj 2236 Wireless Network (并查集)

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

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

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

  4. POJ 2236 Wireless Network ||POJ 1703 Find them, Catch them 并查集

    POJ 2236 Wireless Network http://poj.org/problem?id=2236 题目大意: 给你N台损坏的电脑坐标,这些电脑只能与不超过距离d的电脑通信,但如果x和y ...

  5. [并查集] POJ 2236 Wireless Network

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 25022   Accepted: 103 ...

  6. poj 2236:Wireless Network(并查集,提高题)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 16065   Accepted: 677 ...

  7. POJ 2236 Wireless Network(并查集)

    传送门  Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 24513   Accepted ...

  8. POJ 2236 Wireless Network (并查集)

    Wireless Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/A Description An earthqu ...

  9. [ An Ac a Day ^_^ ] [kuangbin带你飞]专题五 并查集 POJ 2236 Wireless Network

    题意: 一次地震震坏了所有网点 现在开始修复它们 有N个点 距离为d的网点可以进行通信 O p   代表p点已经修复 S p q 代表询问p q之间是否能够通信 思路: 基础并查集 每次修复一个点重新 ...

随机推荐

  1. Windows 上面优秀的工具软件推荐

    Windows 上面优秀的工具软件推荐 一.下载软件 1.速盘 - 度盘神器 简介: 使百度网盘保持全速下载免受限速困扰! 下载: speedpan 2.http下载工具 百度网盘破解下载器:prox ...

  2. eclipse 查看jdk源码

    eclipse中引入jdk源码的设置:  设置: 1.点 "window"-> "Preferences" -> "Java" ...

  3. CF1025B Weakened Common Divisor【数论/GCD/思维】

    #include<cstdio> #include<string> #include<cstdlib> #include<cmath> #include ...

  4. 洛谷P1955 [NOI2015] 程序自动分析 [并查集,离散化]

    题目传送门 题目描述 在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足. 考虑一个约束满足问题的简化版本:假设x1,x2,x3...代表程序中出现的变量,给定n个形如xi=xj或x ...

  5. 洛谷P2874 [USACO07FEB]新牛棚Building A New Barn [贪心]

    题目传送门 题目描述 After scrimping and saving for years, Farmer John has decided to build a new barn. He wan ...

  6. 使用kubeadm搭建kubernetes1.10集群 Posted on April 14, 2018

    https://blog.qikqiak.com/post/use-kubeadm-install-kubernetes-1.10/ kubeadm是Kubernetes官方提供的用于快速安装 Kub ...

  7. Linux命令之who

    who [选项] … [FILE | ARG1 ARG2] 打印有关当前登录用户的信息. (1).选项 -a,--all 同-b –d –login –p –r –t –T -u -b,--boot ...

  8. Linux运维 -- 文件备份同步系列

    [1.]文件备份与恢复 #()整盘数据备份-->另一个盘/一个image文件 dd if=/dev/sdb of=/dev/sde #备份到指定的image文件中 dd if=/dev/sdb ...

  9. 【区间dp】【四边形不等式】CDOJ1653 最小生成树?

    四边形不等式优化的资料去网上找下吧!很多. 可以证明,这个题里面,合并的代价满足较小区间+较大区间<=交错区间. 可以自己画个图看看. #include<cstdio> #inclu ...

  10. XMPP资源绑定(Resource Binding)与单台设备登录控制

    原文:http://blog.csdn.net/brasbug/article/details/26353511 一个XMPP的账号由三部分组成: 用户名(user/node),域名(domain)和 ...