poj 2236 Wireless Network(并查集)

网友投稿 578 2022-08-27

poj 2236 Wireless Network(并查集)

poj 2236 Wireless Network(并查集)

题目:​​Network

Time Limit: 10000MS

 

Memory Limit: 65536K

Total Submissions: 19744

 

Accepted: 8282

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 #include using namespace std;const int maxn=1010;int father[maxn],que[maxn],top;struct node{ int x,y; bool ok;}point[maxn];int find(int x){ if(x==father[x]) return x; return father[x]=find(father[x]);}int doubledist(node a,node b){ return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}int main(){ //freopen("cin.txt","r",stdin); int n,d; cin>>n>>d; top=0; for(int i=0;i

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:编程语言中一些令人抓狂的规则
下一篇:poj 1700 Crossing River(贪心·dp)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~