package pic3;
public class group {
int m,n,s;
int teamx=new int[300000];
int teamy=new int[300000];
int teamnumber;
int group=new int[300000];
int subg=new int[300000];
int groupnumber;
int tx,g,number;
int mode;
void makedata(){
g=1;
s=fastgroup();
group[s]=g;
subg[1]=s;
groupnumber=1;
makegroup(g);
mode=0;
while(mode<50){
g=g+1;
s=fastgroup();
group[s]=g;
subg[1]=s;
groupnumber=1;
makegroup(g);
if(count()==0)mode=100;
}
number=g;
}
int fastgroup(){
int tx,txs,h;
txs=0;
for(tx=1;tx<teamnumber+1;tx++){
h=0;
if(group[tx]==0)h=h+1;
if(txs==0)h=h+1;
if(h==2)txs=tx;
}
return txs;
}
int count(){
int tx,c1;
c1=0;
for(tx=1;tx<teamnumber+1;tx++){
if(group[tx]==0)c1=c1+1;
}
return c1;
}
void makegroup(int g){
int sx,mode;
int cx;
sx=0;
mode=0;
while(mode<50){
sx=sx+1;
s=subg[sx];
check(s);
if(sx==groupnumber)mode=100;
}
}
void check(int s){
int tx,h,z;
for(tx=1;tx<teamnumber+1;tx++){
h=0;
if(met(s,tx)==1)h=h+1;
if(group[tx]==0)h=h+1;
if(h==2)groupnumber=groupnumber+1;
if(h==2)group[tx]=g;
if(h==2)subg[groupnumber]=tx;
}
}
int met(int s1,int s2){
int x1,y1,x2,y2,z1;
x1=teamx[s1];
y1=teamy[s1];
x2=teamx[s2];
y2=teamy[s2];
z1=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
return z1;
}
}