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 这个题提醒一定要注意数据范围,用int是不行的,必须用double
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;
const int MAXN=;
const double eps=1e-;
int F[MAXN];
int find(int x)
{
if(F[x]==-)return x;
return F[x]=find(F[x]);
}
void bing(int u,int v)
{
int t1=find(u),t2=find(v);
if(t1!=t2)F[t1]=t2;
}
struct Node
{
double x,y;
}node[MAXN];
double dis(Node a,Node b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool g[MAXN][MAXN]; bool used[MAXN]; int main()
{
int n,d;
memset(g,false,sizeof(g));
memset(used,false,sizeof(used));
memset(F,-,sizeof(F));
scanf("%d%d",&n,&d);
for(int i=;i<=n;i++)
scanf("%lf%lf",&node[i].x,&node[i].y);
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(dis(node[i],node[j])<d+eps)
g[i][j]=true;
char op[];
int u,v;
while(scanf("%s",&op)==)
{
if(op[]=='O')
{
scanf("%d",&u);
if(!used[u])
{
for(int i=;i<=n;i++)
if(used[i]&&g[u][i])
bing(u,i);
used[u]=true;
}
}
else
{
scanf("%d%d",&u,&v);
if(find(u)==find(v))printf("SUCCESS\n");
else printf("FAIL\n");
}
}
return ;
}

[kuangbin带你飞]专题五 并查集 A - Wireless Network的更多相关文章

  1. [kuangbin带你飞]专题五 并查集

    并查集的介绍可以看下https://www.cnblogs.com/jkzr/p/10290488.html A - Wireless Network POJ - 2236 An earthquake ...

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

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

  3. [kuangbin带你飞]专题1-23题目清单总结

    [kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 Fli ...

  4. 【算法系列学习三】[kuangbin带你飞]专题二 搜索进阶 之 A-Eight 反向bfs打表和康拓展开

    [kuangbin带你飞]专题二 搜索进阶 之 A-Eight 这是一道经典的八数码问题.首先,简单介绍一下八数码问题: 八数码问题也称为九宫问题.在3×3的棋盘,摆有八个棋子,每个棋子上标有1至8的 ...

  5. [kuangbin带你飞]专题十一 网络流

            ID Origin Title   34 / 81 Problem A POJ 3436 ACM Computer Factory   92 / 195 Problem B POJ 3 ...

  6. [ An Ac a Day ^_^ ] [kuangbin带你飞]专题六 最小生成树 POJ 1251 Jungle Roads

    题意: 有n个点 每个点上有一些道路 求最小生成树 解释下输入格式 A n v1 w1 v2 w2 A点上有n条边 A到v1权值是w1 A到v2权值是w2 思路: 字符串处理之后跑kruskal求最小 ...

  7. 【算法系列学习】Dijkstra算法变形 [kuangbin带你飞]专题四 最短路练习

    https://vjudge.net/contest/66569#problem/B 类试题:noip2013 货物运输 POJ 1797 Heavy Transportation 方法一:Dijks ...

  8. 并查集-E - Wireless Network

    E - Wireless Network An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical t ...

  9. [kuangbin带你飞]专题十五 数位DP

            ID Origin Title   62 / 175 Problem A CodeForces 55D Beautiful numbers   30 / 84 Problem B HD ...

随机推荐

  1. Android 性能优化(25)*性能工具之「Systrace」Analyzing UI Performance with Systrace:用Systrace得到ui性能报告

    Analyzing UI Performance with Systrace In this document Overview 简介 Generating a Trace  生成Systrace文件 ...

  2. Spring 侵入式和非侵入式

    1.非侵入式的技术体现 允许在应用系统中自由选择和组装Spring框架的各个功能模块,并且不强制要求应用系统的类必须从Spring框架的系统API的某个类来继承或者实现某个接口. 2.如何实现非侵入式 ...

  3. Windows 7上安装Microsoft Loopback Adapter(微软环回网卡)

    Oracle 安装过程中,先决条件检查遇到如下错误: 正在检查网络配置要求...  检查完成.此次检查的总体结果为: 失败 <<<<  问题: 安装检测到系统的主 IP 地址是 ...

  4. 总结MySQL中SQL语法的使用

    --where子句操作符: where子句操作符 = 等于 <> 不等于(标准语法) != 不等于(非标准语法,可移植性差) < 小于 <= 小于等于 > 大于 > ...

  5. linux下jdk与tomcat的安装与配置

    Linux中jdk与tomcat的安装与配置 1.搭建环境: (1)Linux环境:CentOS6.1 (2)jdk-1.8 (3)tomcat-9.0 2.在Linux系统上创建目录 在usr/lo ...

  6. cocos2dx在windows下搭建环境android报错

    报错:Program bash is not found in PATH   (如果按照我的方法来的话是没有这个错误的,我之前用别的方法的时候有但是后来还是没解决,写出来放到这里做参考吧) 参考原文: ...

  7. 关于微信小程序:scroll-view,backgroundTextStyle

    踩过的坑mark下 1.滚动列表最好不要用scroll-view组件,这个组件有不少问题,比如触顶操作触发了,会连续好几次执行触发函数,得用一个开关变量和定时器配合来控制,一般情况下view组件就够用 ...

  8. 2014中秋节,用java为QQ游戏美女找茬写辅助

    引子        今年中秋闲在家,总要找点事做.        前几天开始学python,很早之前就有计划拿下这门语言了,可惜一直拖到现在……不可否认,我也是个拖沓症患者.在学习python的过程中 ...

  9. UVM基础之---------uvm factory机制register

    factory机制的一大特点就是根据类的名字来创建类的实例. factory 机制中根据类名来创建类的实例所用到的技术:一是参数化的类,二是静态变量和静态函数.这两者是factory机制实现的根本所在 ...

  10. luogu P4172 [WC2006]水管局长 LCT维护动态MST + 离线

    Code: #include<bits/stdc++.h> #define maxn 1200000 #define N 120000 using namespace std; char ...