题目链接 4266.无线网络
有木有大佬帮我看看这题错哪了呜呜呜、、、就差最后一个数据没过了
错误的代码:
#include <bits/stdc++.h>
using namespace std;
const int N=1010;
int p[N],st[N];
vector<pair<int,int>>v;
int n,d;
int find(int x)
{
if(x!=p[x])p[x]=find(p[x]);
return p[x];
}
int main()
{
cin>>n>>d;
v.push_back({-1,-1});
for(int i=1;i<=n;i++)
{
p[i]=i;
int x,y;
cin>>x>>y;
v.push_back({x,y});
}
char k;
while(cin>>k)
{
int a,b;
if(k=='O')//开机
{
cin>>a;
st[a]=1;
for(int i=1;i<=n;i++)
{
if(st[i]==1)
{
int dist=sqrt(pow(v[a].first-v[i].first,2)+pow(v[a].second-v[i].second,2));
if(dist<=d)p[find(a)]=find(i);
}
}
}
else
{
cin>>a>>b;
a=find(a);
b=find(b);
if(a!=b)cout<<"FAIL"<<endl;
else cout<<"SUCCESS"<<endl;
}
}
}
提问于15天前
4597