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. PHP 扩展安装

    PHP版本 >= 5.6.4 PHP扩展:OpenSSL   --- 已经有啦 PHP扩展:PDO PHP扩展:Mbstring PHP扩展:Tokenizer PHP扩展:XML .安装php ...

  2. javascript 的回调函数

    既然函数可以像其他数据那样赋值给某个个变量,可以被定义.删除.拷贝,那为什么就不能被当成参数传递给其他函数呢? 下面的示例中,我们定义了一个以两个函数为参数的函数.该函数会分别执行这两个参数函数,并返 ...

  3. 腾讯QQ的聊天记录中的图片记录造假

    前不久和朋友在群里聊天时,突然出现了一个BUG,就是一个群友发了A图片,但在我这边显示得却是B图片.当时就猜测,腾讯为了节省流量或者手机资源的原因,给每一张图片弄了个唯一ID,遇到相同ID的就直接从本 ...

  4. Codeforces Round #113 (Div. 2) Tetrahedron(滚动DP)

    Tetrahedron time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  5. 31、Flask实战第31天:cms后台修改密码

    cms后台修改密码界面布局 先创建cms_resetpwd.html页面,继承cms_base.html {% extends 'cms/cms_base.html' %} {% block titl ...

  6. Web应用扫描测试工具Vega

    Web应用扫描测试工具Vega   Vega是Kali Linux提供的图形化的Web应用扫描和测试平台工具.该工具提供代理和扫描两种模式.在代理模式中,安全人员可以分析Web应用的会话信息.通过工具 ...

  7. [NOIP2017]时间复杂度(模拟)

    sscanf读入数字,getline(cin,string)读一整行,其余暴力模拟即可. #include<cstdio> #include<string> #include& ...

  8. 【计算几何】【极角排序】Gym - 101174B - Bribing Eve

    把每件物品当成平面上一个点,将第一件物品放在原点.那个权重值相当于一条直线,于是相当于直线绕原点转一圈,统计上侧点的数量. 队友的代码: #include <cmath> #include ...

  9. 用flask开发个人博客(26)—— 利用config.py配置文件动态的创建不同的Flask对象

    原文:https://blog.csdn.net/hyman_c/article/details/52877704 对配置进行封装的目的是根据不同的使用场景,给flask的app赋予不同的config ...

  10. [转] javax.servlet.jar - jar not loaded问题解决

    把那个jsp-api.jarservlet-api.jar删除即可! Details:把 webapps\maintenance\WEB-INF\lib\ 下面的 servlet-api.jar 删掉 ...