Topic Links:
http://acm.hdu.edu.cn/showproblem.php?pid=3549
Main topic:
Give you a weighted graph of N-node m-bars, the source point is 1, the meeting point is N, and the maximum flow of this graph is obtained.
Ideas:
This problem is the bare topic of the network flow to find the maximum flow. it can be done directly with the EDMOND-KARP algorithm.
AC Code:
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include < queue>using namespace Std;const int maxn = 20;const int maxm = 2020;int map[maxn][maxn],pre[maxn],n,m;bool EkBFS (int st Art,int end) {queue<int> Q; BOOL VIS[MAXN]; memset (vis,false,sizeof (VIS)); memset (pre,-1,sizeof (pre)); Q.push (start); Vis[start] = true; while (! Q.empty ()) {int u = q.front (); if (U = = end) return true; Q.pop (); for (int i = 0; I <= N; ++i) {if (Map[u][i] &&!vis[i]) {Vis[i] = t Rue Pre[i] = u; Q.push (i); }}} return false;} int ekmaxflow (int start,int end) {int v,ans = 0,minn; while (EKBFS (Start,end)) {minn = 0xffffff0; v = end; while (pre[v]! =-1) {minn = min (Minn,map[pre[v]][v]); v = pre[v]; } Ans + = Minn; v = end; while (pre[v]! =-1) {MAP[PRE[V]][V]-= Minn; MAP[V][PRE[V]] + = Minn; v = pre[v]; }} return Ans; int main () {int t,u,v,w, Kase = 0; scanf ("%d", &t); while (t--) {memset (map,0,sizeof (MAP)); scanf ("%d%d", &n,&m); for (int i = 0; i < M; ++i) {scanf ("%d%d%d", &u,&v,&w); MAP[U][V] + = W; } printf ("Case%d:%d\n", ++kase, Ekmaxflow (1,n)); } return 0;}
HDU3549 flow problem "Maximum Flow" "Edmond-karp"