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. 使用for循环打印9×9乘法表

    请使用for循环,倒序打印9×9乘法表. 打印结果如下图所示: 使用for循环打印9×9乘法表 #include <stdio.h> int main() { int i, j, resu ...

  2. Java Control Statements

    Java Control Statements Java For Loop public class ForExample1 { public static void main(String[] ar ...

  3. Ubuntu Nginx

    如果是阿云的ECS服务器,默认是已经安装了Apache服务器的,但一般都用不到,可以选择将它卸载 sudo service apache2 stop update-rc.d -f apache2 re ...

  4. 乱侃OOD

    接口代表的就是共同性,所谓面向接口编程,就是要抽象各种不同概念的共同点 然后把这些概念的不同点用具体的类包装起来,这样一看,面向接口编程就等于面向对象编程 其实说白了是一个概念 IOC就是要把对细节的 ...

  5. IoC控制反转和DI依赖注入

    控制反转(Inversion of Control,英文缩写为IoC)是框架的重要特征,并非面向对象编程的专用术语.它与依赖注入(Dependency           Injection,简称DI ...

  6. python excellent code link

    1. Howdoi Howdoi is a code search tool, written in Python. 2. Flask Flask is a microframework for Py ...

  7. WebDAV服务漏洞利用工具DAVTest

    WebDAV服务漏洞利用工具DAVTest   WebDAV是基于Web服务的扩展服务.它允许用户像操作本地文件一样,操作服务器上的文件.借助该功能,用户很方便的在网络上存储自己的文件.为了方便用户使 ...

  8. BZOJ2462[Beijing2011]矩阵模板(二维Hash)

    二维矩阵匹配问题,至今不知道Q的范围是多少,反正是要求做到读入复杂度. 二维Hash:就是一维的等效拓展,注意两维的Base不能相同. 其余就是一维Hash和二维前缀和的结合,可以自然溢出,据说概率很 ...

  9. 【Kruskal】Slim Span

    [Uva1395]Slim Span 题目略…… 试题分析:codevs1001舒适的路线上加一个判一下连通性就好,顺便把除改成减 代码: #include<iostream> #incl ...

  10. 【DFS】STAMPS

    [Poj1010]STAMPS Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18867   Accepted: 5469 ...