# bzoj2127: happiness

1 2
1 1
100 110
1
1000

## Sample Output

1210
【样例说明】

【数据规模】

code：
 1 #include<cstdio>
2 #include<iostream>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 #define maxn 10005
7 #define maxm 550000
8 #define inf 1061109567
9 using namespace std;
10 char ch;
11 bool ok;
13     for (ok=0,ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=1;
14     for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());
15     if (ok) x=-x;
16 }
17 int n,m,a[105][105],b[105][105],c[105][105],d[105][105],ans;
18 struct flow{
19     int s,t,tot,now[maxn],son[maxm],pre[maxm],val[maxm];
21     bool bo[maxn];
22     void init(){s=0,t=n*m+1,tot=1,memset(now,0,sizeof(now));}
23     void put(int a,int b,int c){pre[++tot]=now[a],now[a]=tot,son[tot]=b,val[tot]=c;}
24     void add(int a,int b,int c){put(a,b,c),put(b,a,0);}
25     bool bfs(){
26         memset(bo,0,sizeof(bo));
30             for (int p=now[u],v=son[p];p;p=pre[p],v=son[p])
31                 if (val[p]&&!bo[v]) bo[v]=1,dis[v]=dis[u]+1,list[++tail]=v;
32         }
33         return bo[t];
34     }
35     int dfs(int u,int rest){
36         if (u==t) return rest;
37         int ans=0;
38         for (int p=now[u],v=son[p];p&&rest;p=pre[p],v=son[p])
39             if (val[p]&&dis[v]==dis[u]+1){
40                 int d=dfs(v,min(rest,val[p]));
41                 val[p]-=d,val[p^1]+=d,ans+=d,rest-=d;
42             }
43         if (!ans) dis[u]=-1;
44         return ans;
45     }
46     int dinic(){
47         int ans=0;
48         while (bfs()) ans+=dfs(s,inf);
49         return ans;
50     }
51 }f;
52 inline int calc(int a,int b){return (a-1)*m+b;}
53 int main(){
55     for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) read(a[i][j]);
56     for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) read(b[i][j]);
57     for (int i=1;i<=n;i++) for (int j=1;j<=m;j++){
58         int u=calc(i,j);
60         ans+=a[i][j]+b[i][j];
61     }
62     for (int i=1;i<n;i++) for (int j=1;j<=m;j++) read(c[i][j]);
63     for (int i=1;i<n;i++) for (int j=1;j<=m;j++) read(d[i][j]);
64     for (int i=1;i<n;i++) for (int j=1;j<=m;j++){
65         int u=calc(i,j),v=calc(i+1,j);
69         ans+=c[i][j]+d[i][j];
70     }
71     for (int i=1;i<=n;i++) for (int j=1;j<m;j++) read(c[i][j]);
72     for (int i=1;i<=n;i++) for (int j=1;j<m;j++) read(d[i][j]);
73     for (int i=1;i<=n;i++) for (int j=1;j<m;j++){
74         int u=calc(i,j),v=calc(i,j+1);
82 }