简单结论+并查集+大力模拟
注意并查集不要写挂。
另:记住long double的范围小于long long
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
#define eps 1E-9
long long n,h,r;
inline double clac(const long long &x1,const long long &y1,const long long &z1,const long long &x2,const long long &y2,const long long &z2){
return (double)sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
}
long long f[1005],x[1005],y[1005],z[1005];
inline long long fa(const long long &x){
return (f[x]==x)?(x):(f[x]=fa(f[x]));
}
inline void uni(const long long &x,const long long &y){
(fa(x)==fa(y))?0:f[fa(x)]=fa(y);
}
bool up[1005],dn[1005];
void init(){
scanf("%lld%lld%lld",&n,&h,&r);
memset(up,0,sizeof(up));
memset(dn,0,sizeof(dn));
for(int i=1;i<=n;++i){
f[i]=i;
}
long long nx,ny,nz;
for(int i=1;i<=n;++i){
scanf("%lld%lld%lld",&nx,&ny,&nz);
x[i]=nx;
y[i]=ny;
z[i]=nz;
if(z[i]<=r){
dn[i]=1;
}
if(h-z[i]<=r){
up[i]=1;
}
}
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j){
if(fa(i)==fa(j)){
continue;
}
if((double)(r*2)>=clac(x[i],y[i],z[i],x[j],y[j],z[j])){
uni(i,j);
}
}
}
for(int i=1;i<=n;++i){
if(!dn[i]){
continue;
}
for(int j=1;j<=n;++j){
if(!up[j]){
continue;
}
if(fa(i)==fa(j)){
puts("Yes");
return;
}
}
}
puts("No");
}
int main(){
int T;
scanf("%d",&T);
while(T--){
init();
}
return 0;
}