坑死我了,原来时间限制是10s。
既然这样那就很简单了,每修复一个电脑,遍历所有电脑,能连接就连接。并查集,并炸鸡……我这只鸡……
上代码:
#include
#include
using namespace std;
const int maxn = 1010;
struct node
{
int x, y;
} p[1010];
bool isr[maxn];
int father[maxn];
int n, d;
char o;
int gf(int x)
{
if(father[x] == x) return x;
else return father[x] = gf(father[x]);
return father[x];
}
void un(int x, int y)
{
int fx = gf(x), fy = gf(y);
if(fx == fy) return ;
else father[fx] = fy;
}
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("in.txt", "r", stdin);
#endif
scanf("%d %d", &n, &d);
for(int i = 1; i <= n; i++)
scanf("%d %d", &p[i].x, &p[i].y);
memset(isr, false, sizeof(isr));
for(int i = 1; i <= n; i++)
father[i] = i;
while(scanf("%c", &o) != EOF)
{
if(o == 'O')
{
int a;
scanf("%d",&a);
isr[a] = true;
for(int i=1;i<=n;i++)
if(isr[i])
{
int dx=p[a].x-p[i].x,dy=p[i].y-p[a].y;
if(dx*dx+dy*dy<=d*d)
un(a,i);
}
}
else if(o == 'S')
{
int x, y;
scanf("%d %d", &x, &y);
if(isr[x] == false || isr[y] == false)
printf("FAIL\n");
else
{
int fx = gf(x), fy = gf(y);
if(fx == fy) printf("SUCCESS\n");
else printf("FAIL\n");
}
}
}
return 0;
}