#P4001. [ICPC-Beijing 2006] 狼抓兔子
[ICPC-Beijing 2006] 狼抓兔子
Description
Kids now love "Pleasant Goat and Big Big Wolf" (Xi Yangyang yu Hui Tailang). Although Big Big Wolf fails to catch goats, he is quite good at catching rabbits. The rabbits here are rather slow-witted and have only two burrows. As the Wolf King, you face a terrain shaped like a grid:

The upper-left point is , and the lower-right point is (in the figure, , ). There are three types of roads:
The weight on a road indicates the maximum number of rabbits that can pass through that road; roads are undirected. The upper-left and lower-right corners are the two burrows of the rabbits. Initially, all rabbits gather in the upper-left burrow at , and now they want to run to the lower-right burrow at . The Wolf King starts to ambush these rabbits. To be safe, if the maximum number of rabbits that can pass through a road is , the Wolf King needs to assign the same number of wolves to completely block this road. You need to help the Wolf King plan an ambush so that, while ensuring all rabbits are captured, the number of participating wolves is minimized, since the wolves still need to trouble Pleasant Goat later.
Input Format
The first line contains two integers , indicating the size of the grid.
Then the input consists of three parts.
- Part 1: lines, each containing numbers, representing the weights of horizontal roads.
- Part 2: lines, each containing numbers, representing the weights of vertical roads.
- Part 3: lines, each containing numbers, representing the weights of diagonal roads.
Output Format
Output a single integer, the minimum number of wolves needed for the ambush.
3 4
5 6 4
4 3 1
7 5 3
5 6 7 8
8 7 6 5
5 5 5
6 6 6
14
Hint
Constraints
For all test points, it is guaranteed that , and all road weights are positive integers not exceeding .
Translated by ChatGPT 5
京公网安备 11011102002149号