#include<cstdio>
#include<cstring>
#include<cmath>
typedef long long ll;
const int N=1005,M=2004005;
int t,n,h,r,tot;
struct node
{
int x,y,z;
}nm[N];
int first[N],next[M],end[M];
bool vis[N];
inline void addedge(int u,int v)
{
tot++;
next[tot]=first[u];
first[u]=tot;
end[tot]=v;
}
inline ll dist(node a,node b)
{
return 1ll*(a.x-b.x)*(a.x-b.x)+1ll*(a.y-b.y)*(a.y-b.y)+1ll*(a.z-b.z)*(a.z-b.z);
}
void dfs(int u)
{
vis[u]=1;
for(int j=first[u];j!=0;j=next[j])
if(vis[end[j]]==0)
dfs(end[j]);
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&h,&r);
for(int i=1;i<=n;i++)
scanf("%d%d%d",&nm[i].x,&nm[i].y,&nm[i].z);
tot=0;
memset(first,0,sizeof(first));
memset(next,0,sizeof(next));
memset(end,0,sizeof(end));
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
if(dist(nm[i],nm[j])<=4ll*r*r)
{
addedge(i,j);
addedge(j,i);
}
for(int i=1;i<=n;i++)
{
if(h-nm[i].z<=r&&h-nm[i].z>=-r)
{
addedge(i,n+1);
addedge(n+1,i);
}
if(nm[i].z<=r&&nm[i].z>=-r)
{
addedge(0,i);
addedge(i,0);
}
}
memset(vis,0,sizeof(vis));
dfs(0);
if(vis[n+1])
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 3.441 ms | 15 MB + 320 KB | Accepted | Score: 10 | 显示更多 |
Testcase #2 | 11.585 ms | 15 MB + 320 KB | Accepted | Score: 10 | 显示更多 |
Testcase #3 | 3.991 ms | 15 MB + 320 KB | Accepted | Score: 10 | 显示更多 |
Testcase #4 | 11.585 ms | 15 MB + 320 KB | Accepted | Score: 10 | 显示更多 |
Testcase #5 | 7.301 ms | 15 MB + 344 KB | Accepted | Score: 10 | 显示更多 |
Testcase #6 | 13.858 ms | 15 MB + 356 KB | Accepted | Score: 10 | 显示更多 |
Testcase #7 | 26.802 ms | 15 MB + 364 KB | Accepted | Score: 10 | 显示更多 |
Testcase #8 | 25.257 ms | 15 MB + 356 KB | Accepted | Score: 10 | 显示更多 |
Testcase #9 | 26.191 ms | 15 MB + 360 KB | Accepted | Score: 10 | 显示更多 |
Testcase #10 | 26.294 ms | 15 MB + 360 KB | Accepted | Score: 10 | 显示更多 |