21692_FlowsinGrid

2022-5-16 18:20| 发布者: Hocassian| 查看: 24| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505764887100-Problem List-采集的数据-后羿采集器.html

Pro.ID

21692

Title

Flows in Grid

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21692

AC

2

Submit

15

Ratio

13.33%

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others)
  • 描述

    The maximum flow problem in general graph is so hard that bob doesn't know how to solve it. So bob want to try an easy one, the maximum flow in grid. But this easier one is still too hard for bob. Now here is his problem, please help him:

    Given you a N*M grid as followed, edges of the grid represent pipes which the water can run through; the number of the edge is the capacity of the pipe. For example the capacity of the edge between (0, 0) and (1, 0) is 6, it means that at most 6 units of water can run through this edge (pipe).

    So what is the maximum flow from S to T in the grid? In other words, at most how many units of water can run through from S to T at a time?

    输入

    The first line of the input is a positive integer T. T is the number of the test cases followed.

    The first line of each test case is two positive integers N ( 1 < N < 100 ) and M ( 1 < M < 100 ). And then two integer matrices H( N*(M-1) ) and V( (N-1)*M )follow. H[i][j] is the capacity of the edge between (i, j) and (i, j+1). V[i][j] is the capacity of the edge between (i, j) and (i+1, j). All integers in H and V are non-negative and smaller than 1010.

    输出

    Description

    The maximum flow problem in general graph is so hard that bob doesn't know how to solve it. So bob want to try an easy one, the maximum flow in grid. But this easier one is still too hard for bob. Now here is his problem, please help him:

    Given you a N*M grid as followed, edges of the grid represent pipes which the water can run through; the number of the edge is the capacity of the pipe. For example the capacity of the edge between (0, 0) and (1, 0) is 6, it means that at most 6 units of water can run through this edge (pipe).

    So what is the maximum flow from S to T in the grid? In other words, at most how many units of water can run through from S to T at a time?

    Input

    The first line of the input is a positive integer T. T is the number of the test cases followed.

    The first line of each test case is two positive integers N ( 1 < N < 100 ) and M ( 1 < M < 100 ). And then two integer matrices H( N*(M-1) ) and V( (N-1)*M )follow. H[i][j] is the capacity of the edge between (i, j) and (i, j+1). V[i][j] is the capacity of the edge between (i, j) and (i+1, j). All integers in H and V are non-negative and smaller than 1010.

    Output

    The output of each test case is an integer in one line, the maximum flow of the grid between S(0, 0) and T(N-1, M-1). No redundant spaces are needed.

    Sample Input

    1
    3 3
    0 1
    2 3
    4 5
    6 7 8
    9 10 11

    Sample Output

    6

    Hint

    Here is one of the maximum flows of the example grid above:

    Source

    样例输入

    1
    3 3
    0 1
    2 3
    4 5
    6 7 8
    9 10 11

    样例输出

    6

    提示

    Here is one of the maximum flows of the example grid above:


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部