Code: Select all
"accepted"
Moderator: Board moderators
Code: Select all
"accepted"
Code: Select all
1
4 23
2414 6028
1010 1508
4244 743
9021 2690
1265 5478
2918 5462
3574 8662
7098 5207
4110 2662
2624 748
651 5884
3873 6556
8707 397
7093 3177
5930 1904
2427 3786
5994 7001
1636 5094
7332 5012
6034 1258
2405 7364
8292 983
5241 7012
My AC code returns..boegel wrote:Can someone who has solved this problem let me know what answer they get for the following input?
Code: Select all
1 4 23 2414 6028 1010 1508 4244 743 9021 2690 1265 5478 2918 5462 3574 8662 7098 5207 4110 2662 2624 748 651 5884 3873 6556 8707 397 7093 3177 5930 1904 2427 3786 5994 7001 1636 5094 7332 5012 6034 1258 2405 7364 8292 983 5241 7012
Code: Select all
1862.61
Thanks a lot for your reply. I was getting 1923.67, and failed to see why that was wrong for quite a while.
Code: Select all
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
long lin[100000],rank[1000000];
struct point
{
double x;
double y;
}p[10000];
struct T
{
long u,v;
double w;
}t[1000000];
int sf(const void *aa,const void *bb)
{
T *p=(T *)aa;
T *q=(T *)bb;
if(p->w >q->w)
return 1;
return -1;
}
void make(long x)
{
lin[x]=x;
rank[x]=0;
}
long find(long z)
{
if(z!=lin[z])
lin[z]=find(lin[z]);
return lin[z];
}
void link(long x,long y)
{
if(rank[x]>rank[y])
lin[y]=x;
else
{
lin[x]=y;
if(rank[x]==rank[y])
rank[x]++;
}
}
int main()
{
long i,j,k,l,m,test,n,x,y;
double f,sum;
scanf("%ld",&test);
while(test--)
{
scanf("%ld%ld",&m,&n);
for(i=0;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
l=0;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
f=((p[i].x-p[j].x)*(p[i].x-p[j].x))+((p[i].y-p[j].y)*(p[i].y-p[j].y));
f=sqrt(f);
t[l].u=i;
t[l].v=j;
t[l].w=f;
l++;
}
}
qsort(t,l,sizeof(t[0]),sf);
for(i=0;i<l;i++)
make(i);
sum=0;
k=n;
for(i=0;i<l;i++)
{
x=find(t[i].u);
y=find(t[i].v);
if(x!=y)
{
link(x,y);
if(sum<t[i].w&&k>m)
sum=t[i].w;
k--;
}
}
printf("%.2lf\n",sum+1e-9);
}
return 0;
}
Code: Select all
Code: Select all
1
3 6
0 1
0 2
0 4
0 5
0 7
0 8
Code: Select all
Removed after AC!! Thanks brianfry
Code: Select all
1
3 6
0 1
0 2
0 4
0 5
0 7
0 8