Wireless Network

Wireless Network


https://vjudge.net/contest/477987#problem/B

#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;
int p[1005];
vector<int> color;
pair<double,double> a[1005];
int n;
double t;
void init(int n)
{
	for(int i=0;i<n;i++)
	{
		p[i]=i;
	}
}
int getroot(int a)
{
	if(p[a]!=a)
	{
		p[a]=getroot(p[a]);
	}
	return p[a];
}
void merge(int a,int b)
{
	int x=getroot(a);
	int y=getroot(b);
	if(x!=y)
	{
		p[y]=x;
	}
}
int main()
{
	cin>>n>>t;
	for(int i=1;i<=n;i++)
	cin>>a[i].first>>a[i].second;
	init(n);
	char z;
	while(cin>>z)
	{
		if(z=='S')
		{
			int c,v;
			cin>>c>>v;
			if(getroot(c)==getroot(v))
			cout<<"SUCCESS"<<endl;
			else cout<<"FAIL"<<endl;
		}
		else if(z=='O')
		{
			int k;
			cin>>k;
			color.push_back(k);
			for(int i=0;i<color.size();i++)
			{
				if(sqrt((a[k].first-a[color[i]].first)*(a[k].first-a[color[i]].first)+(a[k].second-a[color[i]].second)*(a[k].second-a[color[i]].second))<=t)
				merge(k,color[i]);
			}
		}
	}
	return 0;
}

 

posted @ 2022-02-11 14:56  是橙橙吖  Views(156)  Comments(0)    收藏  举报