-
Notifications
You must be signed in to change notification settings - Fork 1
/
CDMN03.cpp
87 lines (71 loc) · 1.57 KB
/
CDMN03.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <bits/stdc++.h>
#define ll long long
#define get(a) scanf("%lld", &a);
#define rep(n) for( ll i = 1; i <= n; i++ )
#define repVector(v) for( typeof(v.begin()) it = v.begin(); it != v.end(); it++ )
#define repSet(s) for( typeof(s.begin()) it = s.begin(); it != s.end(); it++ )
#define all(c) c.begin(), c.end()
#define pb push_back
#define absol(a) ( ( a >= 0 ) ? a : -a )
#define FOR(i,a,b) for( ll i = a; i <= b; i++ )
#define ROF(i,a,b) for( ll i = a; i >= b; i-- )
#define DEBUG(x) cout << "[DEBUG]" << #x << " " << x << endl
#define matrix vector< vector<ll> >
#define F first
#define S second
#define mp make_pair
#define L 2*r
#define R 2*r+1
#define INPFILE freopen("input.in","r",stdin)
using namespace std;
struct node {
ll x;
ll y;
ll z;
};
ll parent[105] = {0};
ll find( ll x ) {
if( parent[x] != x )
parent[x] = find( parent[x] );
return parent[x];
}
void join( ll x, ll y ) {
ll p = find(x);
ll q = find(y);
parent[p] = parent[q];
}
ll d;
bool dist( node p, node q ) {
ll val = ( p.x - q.x )*( p.x - q.x );
val += ( p.y - q.y )*( p.y - q.y );
val += ( p.z - q.z )*( p.z - q.z );
if( val <= d*d )
return 1;
else
return 0;
}
int main() {
ll t; get(t);
while(t--) {
ll n;
get(n); get(d);
vector<node> v;
node q;
q.x = q.y = q.z = 0;
v.pb(q);
FOR(i,1,n) {
node p;
get(p.x); get(p.y); get(p.z);
v.pb(p);
parent[i] = i;
}
FOR(i,1,n)
FOR(j,i+1,n)
if( dist( v[i], v[j] ) )
join(i,j);
set<ll> s;
FOR(i,1,n)
s.insert( find(i) );
cout << s.size() << endl;
}
}