Pagini recente » Cod sursa (job #2158967) | Cod sursa (job #1718570) | Cod sursa (job #78656) | Cod sursa (job #2435502) | Cod sursa (job #1025832)
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#define pb push_back
#define maxn 805
#define inf 0x3f3f3f3f
using namespace std;
struct point{double x,y;} a[maxn];
struct edg{double cst;int A,B;} v[maxn*maxn];
int n,S,D,nr;
int used[maxn],father[maxn],c[maxn][maxn];
double d[maxn],Cost[maxn][maxn];
vector<int> l[maxn];
int flow;
double flowC,solM,solC;
double dist(point a,point b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
void read()
{
point p;
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%lf %lf",&a[i].x,&a[i].y);
for(int i=1;i<=n;i++)
{
scanf("%lf %lf",&p.x,&p.y);
for(int j=1;j<=n;j++)
v[++nr].cst=dist(a[j],p),v[nr].A=j,v[nr].B=i+n;
}
S=0; D=2*n+1;
for(int i=1;i<=n;i++)
l[S].pb(i),l[D].pb(i+n);
}
bool cmp(const edg &a,const edg &b){
return a.cst<b.cst;
}
void update(int k)
{
int x,y;
for(int i=1;i<=2*n;i++)
for(int j=1;j<=2*n;j++)
c[i][j]=Cost[i][j]=0;
for(int i=1;i<=n;i++)
{
l[i].clear(); l[i+n].clear();
l[i].pb(S); l[i+n].pb(D);
c[S][i]=c[i+n][D]=1;
}
for(int i=1;i<=k;i++)
{
x=v[i].A; y=v[i].B; c[x][y]=1;
Cost[x][y]=v[i].cst;
Cost[y][x]=-v[i].cst;
l[x].pb(y); l[y].pb(x);
}
flow=flowC=0;
}
int bellman()
{
queue<int> q;
int k;
for(int i=1;i<=D;i++) d[i]=inf,used[i]=0,father[i]=0;
for(q.push(S),used[S]=1,d[S]=0;!q.empty();q.pop(),used[k]=0)
{
k=q.front();
for(unsigned int i=0;i<l[k].size();i++)
if(c[k][l[k][i]] && d[k]+Cost[k][l[k][i]]<d[l[k][i]])
{
d[l[k][i]]=d[k]+Cost[k][l[k][i]];
father[l[k][i]]=k;
if(!used[l[k][i]])
{
q.push(l[k][i]);
used[l[k][i]]=1;
}
}
}
if(d[D]==inf) return 0;
return 1;
}
void ed_karp()
{
while(bellman())
{
for(int i=D;i!=S;i=father[i])
c[father[i]][i]--,c[i][father[i]]++;
flow++; flowC+=d[D];
}
}
void solve()
{
int step,i;
sort(v+1,v+nr+1,cmp);
for(step=1;step<nr;step<<=1);
for(i=0;step;step>>=1)
if(i+step<=nr)
{
update(i+step);
ed_karp();
if(flow==n) solM=v[i+step].cst,solC=flowC;
else i+=step;
}
}
int main()
{
freopen("adapost.in","r",stdin);
freopen("adapost.out","w",stdout);
read();
solve();
printf("%lf %lf",solM,solC);
fclose(stdin);
fclose(stdout);
return 0;
}