Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 这题有点水，然而开始时还是把平方根漏掉了。。。

Posted by GSWS at 2017-02-18 16:15:19 on Problem 2236
```#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>

using namespace std;
const int maxn=1005;
typedef struct Node{
int x,y;
}node;
node num[maxn];
int fa[maxn];

int find(int a){
if(a==fa[a]) return a;
else return fa[a]=find(fa[a]);
}

void merge(int a,int b){
int ffa=find(a),ffb=find(b);
if(ffa==ffb) return ;
else{
fa[ffa]=ffb;
}
}
double dis(node a,node b){
return (double)((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

int main()
{
int n;
double d;
memset(num,0,sizeof(num));
scanf("%d %lf",&n,&d);
d*=d;
for(int i=1;i<=n;i++)
scanf("%d %d",&num[i].x,&num[i].y);
char c;
int a,b;
while(cin>>c){
if(c=='O'){
scanf("%d",&a);
fa[a]=a;
for(int i=1;i<=n;i++){
if(i==a) continue;
if(fa[i]!=0&&dis(num[i],num[a])<=d){
merge(i,a);
}
}
}
else{
scanf("%d %d",&a,&b);
if(find(a)==find(b))
printf("SUCCESS\n");
else
printf("FAIL\n");
}
}
return 0;
}
```

Followed by: