Wireless Network
Time Limit: 10000MS   Memory Limit: 65536K
Total Submissions: 24497   Accepted: 10213

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

Source

 #include <iostream>
#include <cstdio> #define MAX_N 1000+5 using namespace std; struct point{int x;int y;int jud;};
point p[];
int par[MAX_N];//父节点
int depth[MAX_N];//深度 void init(int n){
for(int i=;i<=n;i++){
par[i]=i;
depth[i]=;
}
}
int find_father(int t){
if(t==par[t]){
return t;
}else{
return par[t]=find_father(par[t]);
//实现了路径压缩
}
}
void unite(int t1,int t2){
int f1=find_father(t1);
int f2=find_father(t2);
if(f1==f2){
return ;
}
if(depth[f1]<depth[f2]){
par[f1]=f2;
}else{
par[f2]=f1;
if(depth[f1]==depth[f2]){
depth[f1]++;
//记录深度
}
}
} bool same(int x,int y){
return find_father(x)==find_father(y);
} int distanc_2(point a,point b){
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
} int main()
{
int n,d;
char c;
int t1,t2;
scanf("%d %d",&n,&d);
init(n);
for(int i=;i<=n;i++){
scanf("%d %d",&p[i].x,&p[i].y);
p[i].jud=;
}
getchar();
while(scanf("%c",&c)!=EOF){
if(c=='O'){
scanf("%d",&t1);
getchar();
p[t1].jud=; for(int i=;i<=n;i++){
if(i!=t1&&p[i].jud==){
if(distanc_2(p[t1],p[i])<=d*d){
unite(t1,i);
}
}
}
}else{
scanf("%d %d",&t1,&t2);
getchar();
if(same(t1,t2)){
printf("SUCCESS\n");
}else{
printf("FAIL\n");
}
}
}
return ;
}

poj2236_并查集_Wireless Network的更多相关文章

  1. POJ 2236 (简单并查集) Wireless Network

    题意: 有n个电脑坏掉了,分别给出他们的坐标 有两种操作,可以O x表示修好第x台电脑,可以 S x y表示x y是否连通 两台电脑的距离不超过d便可连通,两台电脑是连通的可以直接连通也可以间接通过第 ...

  2. [并查集] POJ 2236 Wireless Network

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

  3. POJ 2236 Wireless Network(并查集)

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

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

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

  5. POJ 2236 Wireless Network (并查集)

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

  6. POJ 2236 Wireless Network (并查集)

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

  7. [LA] 3027 - Corporative Network [并查集]

    A very big corporation is developing its corporative network. In the beginning each of the N enterpr ...

  8. LA 3027 Corporative Network 并查集记录点到根的距离

    Corporative Network Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu [S ...

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

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

随机推荐

  1. RTC时钟

    1.设置时间之前取消备份区域(BKP)写保护 主要有两部分组成 1.用来和APB1总线对接,对其进行读写操作 2. 预分频模块:在RTC_CR设置相应的允许,位每个TR_CLK周期中RTC产生一个中断 ...

  2. SharpPcap网络包捕获框架的使用--实例代码在vs2005调试通过

    转自:http://hi.baidu.com/boyxgb/blog/item/89ac86fbdff5f82c4e4aea2e.html 由于项目的需要,要从终端与服务器的通讯数据中获取终端硬件状态 ...

  3. Asp.Net MVC<七>:Model

    Model 指ViewModel ,其作用: 用于目标Action的参数绑定 用于View呈现 Model元数据则是对ViewModel数据类型的描述,其作用在于控制作为Model的数据对象在View ...

  4. CentOS 6.7下利用Rsyslog+LogAnalyzer+MySQL部署日志服务器

    一.简介 LogAnalyzer 是一款syslog日志和其他网络事件数据的Web前端.它提供了对日志的简单浏览.搜索.基本分析和一些图表报告的功能.数据可以从数据库或一般的syslog文本文件中获取 ...

  5. IBatisNet使用教程

     1.是数据持久层,对应.NET方向的有Ibatis.NET,只要用来处理数据库表结构和程序实体之间映射,ado.net是用来处理和数据库直接通信的,取出数据(object,int,string,da ...

  6. ngBind ngBindTemplate ngBindHtml

    ng-bind: 只能绑定一个变量 在AngularJS中显示模型中的数据有两种方式: 一种是使用花括号插值的方式: <p>{{titleStr}}</p> 另一种是使用基于属 ...

  7. php常用字符串函数小结

    php内置了98个字符串函数(除了基于正则表达式的函数,正则表达式在此不在讨论范围),能够处理字符串中能遇到的每一个方面内容,本文对常用字符串函数进行简单的小结,主要包含以下8部分:1.确定字符串长度 ...

  8. 安卓log4k问题解决

    1.直接上代码 //log4k问题 public static void log(String tag, String str) { int index = 0; // 当前位置 int max = ...

  9. zend studio汉化

    在help菜单中选择Install New Software,在 work with栏中添加上这样的地址 http://archive.eclipse.org/technology/babel/upd ...

  10. ThinkPHP中疑难笔记

    不但要记住核心的东西, 还要记住 相关的 东西: 如php cli的版本是 5.6.14 bulit: sep 30, 2015 tp中, 通常说的系统就是框架; 项目就是 "应用程序&qu ...