-
Notifications
You must be signed in to change notification settings - Fork 185
/
10301.cc
52 lines (52 loc) · 1.14 KB
/
10301.cc
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
// https://uva.onlinejudge.org/external/103/10301.pdf
#include<bits/stdc++.h>
using namespace std;
using pt=complex<double>;
using ptd=tuple<pt,double>;
using vptd=vector<ptd>;
using vi=vector<int>;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
for(;;){
int n,u,v;
cin>>n;
if(n==-1)break;
vi s=vi(n, 1),p=vi(n);
for(int i=0;i<n;i++)p[i]=i;
function<int(int)>find=[&](int i){
if(i==p[i])return i;
return p[i]=find(p[i]);
};
function<void(int,int)>unite=[&](int i, int j){
i=find(i);
j=find(j);
if(i==j)return;
if(s[i]<s[j])swap(i,j);
s[i]+=s[j];
p[j]=i;
};
vptd a(n);
for(int i=0;i<n;i++){
double x,y,r;
cin>>x>>y>>r;
a[i]={{x,y},r};
}
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++){
pt x,y;
double r,t;
tie(x,r)=a[i];
tie(y,t)=a[j];
if(r<t){
swap(r,t);
swap(x,y);
}
if(fabs(y-x)<r+t&&fabs(y-x)+t>r)
unite(i,j);
}
int m=0;
for(int i=0;i<n;i++)m=max(m,s[i]);
cout<<"The largest component contains "<<m<<" ring"<<(m!=1?"s":"")<<".\n";
}
}