HDU 3549 Basic network flow EK algorithm flow problem

Source: Internet
Author: User


Welcome to the--bestcoder Anniversary (High quality topic + multiple Rewards)
Flow problem

Time limit:5000/5000 MS (java/others) Memory limit:65535/32768 K (java/others)
Total submission (s): 10184 Accepted Submission (s): 4798


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 the test cases.
For each test case, the first line contains integers N and M, denoting the number of vertexes and edges in the graph. (2 <= N <=, 0 <= M <= 1000)
Next M lines, each line contains three integers X, Y and C, there is a edge from X to Y and the capacity of it is C. (1 & lt;= X, Y <= N, 1 <= C <= 1000)

Outputfor Each test cases, you should output the maximum flow from source 1 to sink N.

Sample Input23 21 2 12 3 13 31 2 12 3 11 3 1

Sample outputcase 1:1case 2:2

Authorhyperhexagon

Source Hyperhexagon ' s Summer Gift (Original tasks)

Recommendzhengfeng | We have carefully selected several similar problems for you:1532 3572 3416 3081 3491
#include <stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<queue>using namespacestd;intdp[ -][ -],pre[ -];Const inttmin=999999999;intMaxflow;voidEK (intStartintEndintN) {     while(1) {Queue<int>Q; Q.push (1); intminflow=tmin; memset (PRE,0,sizeof(pre));  while(!Q.empty ()) {            intu=Q.front ();            Q.pop ();  for(intI=1; i<=n;i++){                if(dp[u][i]>0&&!Pre[i]) {Pre[i]=u;                Q.push (i); }            }        }        if(pre[end]==0)             Break;  for(intI=end;i!=start;i=Pre[i]) {Minflow=min (dp[pre[i]][i],minflow); }         for(intI=end;i!=start;i=Pre[i]) {Dp[pre[i]][i]-=Minflow; Dp[i][pre[i]]+=Minflow; } Maxflow+=Minflow; }}intMain () {intCount=0; intn,m; intT; scanf ("%d",&6);  while(t--) {scanf ("%d%d",&n,&m); Memset (DP,0,sizeof(DP)); memset (PRE,0,sizeof(pre)); Count++; intu,v,w;  for(intI=1; i<=m;i++) {scanf ("%d%d%d",&u,&v,&W); DP[U][V]+=W; } Maxflow=0; EK (1, N,n); printf ("Case %d:%d\n", Count,maxflow); }   return 0;}

HDU 3549 Basic network flow EK algorithm flow problem

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.