Poj 1273 drainage ditches (maximum network Stream)

Source: Internet
Author: User
Drainage ditches
Time limit:1000 ms   Memory limit:10000 K
Total submissions:55893   Accepted:21449

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.
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 ction, but there might be a way that water can flow in a circle.

Input

The input parameter des several cases.For each case, the first line contains two space-separated integers, n (0 <= n <= 200) 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. each of the following n lines contains three integers, Si, EI, and CI. si and ei (1 <= Si, EI <= m) 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 a single integer, the maximum rate at which water may emptied from the pond.

Sample Input

5 41 2 401 4 202 4 202 3 303 4 10

Sample output

50

Source

Usaco 93 start point 1 settlement point N
# Include <iostream> # include <cstdio> # include <cstring> # include <limits> # include <queue> # include <algorithm> using namespace STD; int flow [205] [205], a [205], F [205], MX [205] [205]; int n, m; void pre () {int U, v, value; memset (MX, 0, sizeof (MX); For (INT I = 0; I <n; I ++) {CIN> U> V> value; MX [u] [v] + = value ;}} int solve () {int ans = 0; memset (flow, 0, sizeof (flow); queue <int> q; while (1) {q. push (1); memset (A, 0, sizeof (a); MEMS Et (F, 0, sizeof (f); A [1] = int_max; // start from the starting point every time while (! Q. empty () {// get the traffic of the smallest single arc in the path every time you take a stream and add it to the total traffic int u = Q. front (); q. pop (); For (INT v = 1; v <= m; V ++) {If (! A [v] & MX [u] [v]> flow [u] [v]) {// if the preceding path is not empty and the current maximum capacity is greater than the traffic that has already flowed through the Channel A [v] = min (A [u], MX [u] [v]-flow [u] [v]); // select the smallest f [v] = u; // record the parent node of the path to facilitate updating the stream Q. push (V); // push feasible nodes into the stack. }}} if (! A [m]) return ans; // If the smallest arc is still 0, it indicates that the feasible stream is finished. For (INT v = m; V! = 1; V = f [v]) {// The flow [f [v] [v] + = A [m] of the parent node of the path. // record the traffic that has passed through flow [v] [f [v]-= A [m]; // inverse heaven negative} ans + = A [m]; // Add the traffic of the stream to the minimum value} int main (void) {While (CIN> N> m) {pre (); cout <solve () <Endl ;}return 0 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.