在第四个测试点RE
#include<iostream>
#include<cmath>
#include<queue>
#include<vector>
#include<cstring>
#define int long long
#define lmt(x1,x2,y1,y2,z1,z2) ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2))
using namespace std;
inline int read() {
int x = 0;bool f = 1;char c = getchar();
while(!isdigit(c)) { if(c == '-') f = 0; c = getchar(); }
while(isdigit(c)) x = x * 10 + c - 48,c = getchar();
return f ? x : -x;
}
constexpr int maxn = 2100;
int t,n,h,r;
int x[maxn],y[maxn],z[maxn];
bool vis[maxn];
queue<int> que;
vector<int> down,G[maxn];
bool bfs(int u) {
if(vis[u]) return false;
que.push(u);
vis[u] = true;
while(!que.empty()) {
int head = que.front();
for(int i = 0;i < G[head].size();i++) {
if(vis[G[head][i]]) continue;
if(z[G[head][i]] + r >= h) return true;
vis[G[head][i]] = true;
que.push(G[head][i]);
}
que.pop();
}
return false;
}
signed main()
{
// freopen("t2.in","r",stdin);freopen("t2.out","w",stdout);
// t = read();
cin>>t;
while(t--) {
memset(vis,0,sizeof vis);bool flag = true,flag1 = true;
// n = read(),h = read(),r = read();
cin>>n>>h>>r;
for(int i = 1;i <= n;i++) {
// x[i] = read(),y[i] = read(),z[i] = read();
cin>>x[i]>>y[i]>>z[i];
if(z[i] - r <= 0) down.push_back(i);
if(z[i] - r <= 0 && z[i] + r >= h){
cout << "Yes" << '\n';
flag1 = false;
break;
}
}
if(!flag1) continue;
for(int i = 1;i <= n;i++)
for(int j = i+1;j <= n;j++)
if(lmt(x[i],x[j],y[i],y[j],z[i],z[j]) <= 4 * r * r) G[i].push_back(j),G[j].push_back(i);
// while(!que.empty()) que.pop();
for(int i = 0;i < down.size();i++)
{
while(!que.empty()) que.pop();
if(bfs(down[i])) { cout << "Yes" << '\n'; flag = false; break;}
}
if(flag) cout << "No" << '\n';
for(int i = 1;i <= n;i++) G[i].clear();
down.clear();
}
// fclose(stdin),fclose(stdout);
return 0;
}