Maximum Flow
Time limit2sMemory limit512 MB
Given two paths of n vertices each plus 2n+1 cross edges with huge capacities, find the max flow from (0,0) to (1,n).
- Level
Hard9 of 10
- Topics
- Graph, Shortest path, Greedy, Dynamic programming
- Solved
- No attempts yet
Problem
Bobo has an undirected graph with vertices labeled with the following pairs of integers: . The graph has three classes of edges.
- The edges of the first class connect vertices and with capacity for .
- The edges of the second class connect vertices and with capacity for .
- The edges of the third class connect vertices and with capacity for .
Bobo would like to find the maximum flow from vertex to vertex .
Input
The input contains zero or more test cases, and is terminated by end-of-file. For each test case:
The first line contains an integer ().
The second line contains integers .
The third line contains integers .
The fourth line contains integers .
The constraints are: .
It is guaranteed that the number of test cases does not exceed , and the sum of all does not exceed .
Output
For each test case, output an integer which denotes the maximum flow.