**Title Description** DescriptionYT City is a well-planned city, and the city is divided into nxn areas by the east-west and north-South Main roads. For simplicity, the YT city can be viewed as a square, and each area can also be viewed as a square. Thus, the YT city includes (n+1) x (n+1) intersection and 2NX (n+1) Two-Way road (abbreviated to the road), each two-way road connecting the main road on the two adjacent intersections. A map of the city of YT (n = 2), the city is divided into 2x2 areas, including 3x3 intersections and 12 bidirectional roads.

Small Z as the mayor of the city, he was based on statistical information on the daily peak of the work of YT city in two directions per road traffic, that is, during the peak period along the way through the road of the number of people. Each intersection has a different altitude value, YT city residents think that climbing is a very tiring thing, every height of the climb up H, you need to consume H's strength. If it's downhill, you don't need to expend energy. So if the end of a road is at an altitude minus the starting altitude at H (Note that H is probably negative), then the physical strength of a person passing through this passage is max{0, H} (here Max{a, b} for a, b two values larger).

Small z also measured the intersection of the city's northwest corner at an altitude of 0, the intersection of the southeast corner at an altitude of 1 (as shown), but the altitude of the other intersections is unknown. Little Z wants to know in the best case (i.e. you can arbitrarily assume the altitude of the other intersection), the total force and the minimum value of all people climbing during the peak hours of each day.

**input/output format** input/output

**Input Format:**
The first line contains an integer n, meaning as shown above.

Next 4n (n + 1) lines, each line contains a non-negative integer that represents the person traffic information for each direction of each road. Input order: The number of n (n + 1) indicates all traffic from west to east, then N (n + 1) number represents all traffic from north to south, the number of n (n + 1) represents all traffic from east to west, and finally the number of n (n + 1) represents all people flow from south to north direction. For each direction, the input order is given from the north to the south, if the north-south direction is in the same order from west to east (see sample Input).

**output Format:**
Contains only one number, which represents the overall force (i.e., the total strength and minimum) that is consumed by all the people climbing during the peak hours of each day during the most desirable times, rounded to an integer.

**input and Output sample** sample Input/output

**sample Test point # #**
**Input Sample:**
1

1

2

3

4

5

6

7

8

**Sample output:**
3

**Description** DescriptionAnalysis: As a province of slag, do NOI the original intention is to cheat a bit. The above analysis can be concluded that although the elevation of the node may be a real number, but can only be 0 or 1. Increase the altitude to 1 in the least amount of traffic, so that you can spend less energy in the area where the traffic is greatest. This means that some edges are selected, which divide the source and sink points into two parts. It is obvious that the subject is the smallest cut. As for the minimum cut how to beg that there is a difference. For the AC program, is the use of "floor plan minimum cut = shortest circuit" that is, each square as a point, the box between the two has a forward edge, the weight of the edge to the edge of the edge of the right value. Run SPFA can get 80 points, Heap+dijkstra can successfully AC. If the "minimum cut = Maximum Flow" theorem is used, the dinic can get 50 points for reasonable mapping + array simulation chain list. As for the map, if the maximum flow is obtained, it is possible to save the edge from 2, followed by the reverse edge. This makes it easy to get in the process of finding the opposite edge of the maximum flow. For example, 2 to the positive edge, 3 to the reverse edge. 2^1=3,3^1=2. Can greatly improve the efficiency of the program. 50 min dinic Code:

#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>using namespacestd; inthead[500001],next[500001],list[500001],key[500001],dis[250001],sq[500001],n,x,sum,delta,ans,t; voidInsertintIintJintx) {sum+=2; Next[sum]=Head[i]; Head[i]=sum; List[sum]=J; Key[sum]=x; } BOOLBFS () {memset (DIS,0xFF,sizeof(DIS)); dis[1]=0; intL=0, r=1, X, y; sq[1]=1; while(l<r) {L++; Y=Sq[l]; X=Head[y]; while(x!=0) { if(dis[list[x]]<0&&key[x]>0) {Dis[list[x]]=dis[y]+1; R++; SQ[R]=List[x]; } x=Next[x]; } } if(dis[t]>0)return true;Else return false; } intFindintXintLow ) { if(x==t)returnLow ; intA=0, y=Head[x]; while(y!=0) { if(key[y]>0&&dis[list[y]]==dis[x]+1&& (a=Find (List[y],min (low,key[y)))) {Key[y]-=A; Key[y^1]+=A; returnA; } y=Next[y]; } return 0; } intMain () {scanf ("%d",&N); Sum=0; for(intI=0; i<=n;i++) for(intj=1; j<=n;j++) {scanf ("%d",&x); Insert ((n+1) *i+j, (n+1) *i+j+1, x); } for(intI=0; i<n;i++) for(intj=1; j<=n+1; j + +) {scanf ("%d",&x); Insert (i* (n+1) +j, (i+1) * (n+1)+j,x); } Sum=1; for(intI=0; i<=n;i++) for(intj=1; j<=n;j++) {scanf ("%d",&x); Insert ((n+1) *i+j+1, (n+1) *i+j,x); } for(intI=0; i<n;i++) for(intj=1; j<=n+1; j + +) {scanf ("%d",&x); Insert ((I+1) * (n+1) +j,i* (n+1)+j,x); } t= (n+1) * (n+1); Ans=0; while(BFS ()) while(Delta=find (1,0x7fffffff)) ans+=Delta; printf ("%d", ans); return 0; }

Test point**#1**：**Pass the test point. **Score 10, time consuming 0ms, memory 3088kB.

Test point**#2**：**Pass the test point. **Score 10, time consuming 0ms, memory 3080kB.

Test point**#3**：**Pass the test point. ** score 10, time consuming 0ms, memory 3084kB.

Test point ** #4 **: ** Pass the test point. ** score 10, time consuming 0ms, memory 3096kB.

Test point ** #5 **: ** Pass the test point. ** score 10, time consuming 15ms, memory 3092kB.

Test point ** #6 **: ** exceeds the time limit. ** score 0, memory 3108kB.

Test point ** #7 **: ** exceeds the time limit. ** score 0, memory 3117kB.

Test point ** #8 **: ** exceeds the time limit. ** score 0, memory 3137kB.

Test point ** #9 **: ** exceeds the time limit. ** score 0, memory 11042kB.

Test point ** #10 **: ** exceeds the time limit. ** score 0, memory 11046kB.

[NOI2010] [valley P2046] elevation [[]]