HDU 3549 (the largest stream for getting started with network streams), hdu3133

Source: Internet
Author: User

HDU 3549 (the largest stream for getting started with network streams), hdu3133
Flow ProblemTime Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission (s): 10327 Accepted Submission (s): 4866


Problem DescriptionNetwork flow is a well-known difficult problem for ACMers. Given a graph, your task is to find out the maximum flow for the weighted directed graph.
InputThe first line of input contains an integer T, denoting the number of test cases.
For each test case, the first line contains two integers N and M, denoting the number of vertexes and edges in the graph. (2 <= N <= 15, 0 <= M <= 1000)
Next M lines, each line contains three integers X, Y and C, there is an edge from X to Y and the capacity of it is C. (1 <= X, Y <= N, 1 <= C <= 1000)
OutputFor each test cases, you should output the maximum flow from source 1 to sink N.
Sample Input

23 21 2 12 3 13 31 2 12 3 11 3 1
 
Sample Output
Case 1: 1Case 2: 2
 
AuthorHyperHexagon
SourceHyperHexagon's Summer Gift (Original tasks)

 


N vertices and m edges. Locate 1 to n to maximize the traffic.

Solutions; find all the augmented paths, and then find the edge on the augmented path to find the minimum traffic !!

# Include <cstdio> # include <cmath> # include <queue> # include <iostream> # include <algorithm> # include <cstring> using namespace std; int n, m; int map1 [1001] [1001]; int pre [1001]; int vis [1001]; int s, t; bool BFS () {int I, cur; queue <int> q; memset (pre, 0, sizeof (pre); memset (vis, 0, sizeof (vis); vis [s] = 1; q. push (s); while (! Q. empty () {cur = q. front (); q. pop (); if (cur = t) return 1; for (I = 1; I <= n; I ++) {if (! Vis [I] & map1 [cur] [I]) {q. push (I); pre [I] = cur; vis [I] = 1 ;}}return 0 ;}// find the augmented path int Max_flow () {int I, ans = 0; while (1) {if (! BFS () return ans; int Min = 0x7f7f7f7f; for (I = t; I! = S; I = pre [I]) Min = min (Min, map1 [pre [I] [I]); for (I = t; I! = S; I = pre [I]) {map1 [pre [I] [I]-= Min; map1 [I] [pre [I] + = Min ;} ans + = Min ;}/// find the minimum traffic int main () {int T; cin> T; int v, u, c; int k = 1; while (T --) {scanf ("% d", & n, & m); memset (map1, 0, sizeof (map1 )); s = 1, t = n; while (m --) {scanf ("% d", & u, & v, & c ); map1 [u] [v] + = c;} printf ("Case % d: % d \ n", k ++, Max_flow ();} return 0 ;}

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.