10181_DrainageDitches

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

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

Pro.ID

10181

Title

Drainage Ditches

Title链接

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

AC

116

Submit

405

Ratio

28.64%

时间&空间限制

  • Time Limit: 10000/5000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John has built a set of drainage ditches so that Bessie's clover patch is never covered in water. Instead, the water is drained to a nearby stream. Being an ace engineer, Farmer John has also installed regulators at the beginning of each ditch, so he can control at what rate water flows into that ditch.

    Farmer John knows not only how many gallons of water each ditch can transport per minute but also the exact layout of the ditches, which feed out of the pond and into each other and stream in a potentially complex network. Note however, that there can be more than one ditch between two intersections.

    Given all this information, determine the maximum rate at which water can be transported out of the pond and into the stream. For any given ditch, water flows in only one direction, but there might be a way that water can flow in a circle.

    输入

    Multiple test cases. For each case :

    Line 1:     Two space-separated integers, N ( 0 ≤ N ≤ 100,000 ) and M ( 2 ≤ M ≤ 200 ). N is the number of ditches that Farmer John has dug. M is the number of intersections points for those ditches. Intersection 1 is the pond. Intersection point M is the stream.

    Line 2..N+1:    Each of N lines contains three integers, Si, Ei, and Ci.  Si and Ei ( 1 ≤ Si, EiM ) designate the intersections between which this ditch flows. Water will flow through this ditch from Si to Ei.  Ci ( 0≤ Ci ≤ 10,000,000 ) is the maximum rate at which water will flow through the ditch.

    输出

    Description

    Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John has built a set of drainage ditches so that Bessie's clover patch is never covered in water. Instead, the water is drained to a nearby stream. Being an ace engineer, Farmer John has also installed regulators at the beginning of each ditch, so he can control at what rate water flows into that ditch.

    Farmer John knows not only how many gallons of water each ditch can transport per minute but also the exact layout of the ditches, which feed out of the pond and into each other and stream in a potentially complex network. Note however, that there can be more than one ditch between two intersections.

    Given all this information, determine the maximum rate at which water can be transported out of the pond and into the stream. For any given ditch, water flows in only one direction, but there might be a way that water can flow in a circle.

    Input

    Multiple test cases. For each case :

    Line 1:     Two space-separated integers, N ( 0 ≤ N ≤ 100,000 ) and M ( 2 ≤ M ≤ 200 ). N is the number of ditches that Farmer John has dug. M is the number of intersections points for those ditches. Intersection 1 is the pond. Intersection point M is the stream.

    Line 2..N+1:    Each of N lines contains three integers, Si, Ei, and Ci.  Si and Ei ( 1 ≤ Si, EiM ) designate the intersections between which this ditch flows. Water will flow through this ditch from Si to Ei.  Ci ( 0≤ Ci ≤ 10,000,000 ) is the maximum rate at which water will flow through the ditch.

    Output

    For each case, output one line with a single integer, the maximum rate at which water may emptied from the pond.

    Sample Input

    5 4
    1 2 40
    1 4 20
    2 4 20
    2 3 30
    3 4 10

    Sample Output

    50

    Hint

    最大流问题,是最水的最大流。这题的数据流比较小,所以可以用邻接矩阵表示的Edmonds-Karp算法过,如果数据量大的话,用邻接表表示的Dinic算法效率比较高。此外还有 SAP、Improved SAP、预流推进算法。

    Source

    样例输入

    5 4
    1 2 40
    1 4 20
    2 4 20
    2 3 30
    3 4 10

    样例输出

    50

    提示

    最大流问题,是最水的最大流。这题的数据流比较小,所以可以用邻接矩阵表示的Edmonds-Karp算法过,如果数据量大的话,用邻接表表示的Dinic算法效率比较高。此外还有 SAP、Improved SAP、预流推进算法。


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部