1 #include <algorithm>
2 #include <iostream>
3 #include <cstdlib>
4 #include <cstring>
5 #include <cstdio>
6 #include <cmath>
7 #include <queue>
8 #define maxn 210
9 #define inf 1999999999.0
10 #define RG register
11 using namespace std;
12 struct data{
13 int nex,to,w;
14 double a,b;
15 }g[maxn*maxn*2],e[maxn*maxn*2];
16 double a[maxn][maxn],b[maxn][maxn],dis[maxn];
17 int head[maxn],edge=-1,vis[maxn],pre[maxn];
18 int q[maxn*maxn];
19 inline int Read() {
20 int w;bool q=1;char c;
21 while (((c=getchar())<‘0‘||‘9‘<c)&&c!=‘-‘);
22 if (c==‘-‘) q=0,c=getchar();
23 w=c-‘0‘;
24 while (‘0‘<=(c=getchar())&&c<=‘9‘) w=w*10+c-‘0‘;
25 return q?w:-w;
26 }
27 inline void add(int from,int to,int w,int a,int b){
28 g[++edge].nex=head[from];
29 g[edge].to=to;
30 g[edge].w=w;
31 g[edge].a=a;
32 g[edge].b=b;
33 head[from]=edge;
34 }
35 inline bool SPFA(int s,int t,double kp){
36 for(int i=0;i<=t;i++)
37 dis[i]=-inf;
38 double zd=dis[0];
39 dis[s]=0,vis[s]=1;
40 int h=0,tt=1;
41 q[tt]=s;
42 while(h<tt){
43 int u=q[++h];
44 vis[u]=0;
45 for(RG int i=head[u];i!=-1;i=e[i].nex)
46 if(e[i].w>0 && dis[e[i].to]<dis[u]+(e[i].a-kp*e[i].b)){
47 dis[e[i].to]=dis[u]+(e[i].a-kp*e[i].b);
48 pre[e[i].to]=i;
49 if(!vis[e[i].to]){
50 vis[e[i].to]=1;
51 q[++tt]=e[i].to;
52 }
53 }
54 }
55 if(dis[t]==zd) return 0;
56 else return 1;
57 }
58 inline double end(int s,int t,double kp){
59 int p,sum=inf;
60 double ans=0.0;
61 for(RG int u=t;u!=s;u=e[p^1].to)
62 p=pre[u],sum=min(sum,e[p].w);
63 for(RG int u=t;u!=s;u=e[p^1].to){
64 p=pre[u];
65 e[p].w-=sum;
66 e[p^1].w+=sum;
67 ans+=sum*(e[p].a-kp*e[p].b);
68 }
69 return ans;
70 }
71 inline double solve(int s,int t,double kp){
72 double ans=0.0;
73 while(SPFA(s,t,kp))
74 ans+=end(s,t,kp);
75 return ans;
76 }
77 int main()
78 {
79 freopen("ball.in","r",stdin);
80 freopen("ball.out","w",stdout);
81 int n;
82 scanf("%d",&n);
83 memset(head,-1,sizeof(head));
84 int s=0,t=2*n+1;
85 for(RG int i=1;i<=n;i++)
86 for(RG int j=1;j<=n;j++) a[i][j]=Read();
87 for(RG int i=1;i<=n;i++)
88 for(RG int j=1;j<=n;j++) b[i][j]=Read();
89 for(RG int i=1;i<=n;i++)
90 for(RG int j=n+1;j<=2*n;j++)
91 add(i,j,1,a[i][j-n],b[i][j-n]),add(j,i,0,-a[i][j-n],-b[i][j-n]);
92 for(RG int i=1;i<=n;i++) add(s,i,1,0,0),add(i,s,0,0,0),add(i+n,t,1,0,0),add(t,i+n,0,0,0);
93 RG double r=10000.0,l=0.0;
94 int T=36;
95 while(T){
96 memcpy(e,g,sizeof(g));
97 T--;
98 double mid=(l+r)/2;
99 if(solve(s,t,mid)>=0) l=mid;
100 else r=mid;
101 }
102 printf("%.6lf",r);
103 return 0;
104 }