Question: Give You n sides with the target position T. Next there are each side, including the start point, end point, and capacity;
Feeling: the first code of the largest stream. This question is a deep understanding of the ek algorithm. However, this question is a pitfall, that is, the case of duplicate borders =!
Idea: EK Algorithm
AC code:
#include<stdio.h>#include<string.h>#include<algorithm>#include<queue>using namespace std;#define INF 100000000#define N 202int cap[N][N],flow[N][N];int p[N],a[N];int n,t;int Edmonds_Karp(int s){ int f=0; queue<int >q; while(1) { memset(a,0,sizeof(a)); a[s]=INF; q.push(s); while(!q.empty()) { int u=q.front(); q.pop(); for(int v=1;v<=t;v++) if(!a[v]&&cap[u][v]>flow[u][v]) { p[v]=u; q.push(v); a[v]=min(a[u],cap[u][v]-flow[u][v]); } } if(a[t]==0)break; for(int u=t;u!=s;u=p[u]) { flow[p[u]][u]+=a[t]; flow[u][p[u]]-=a[t]; } f+=a[t]; } return f;}int main(){ int u,v,w,i,j; while(scanf("%d %d",&n,&t)!=EOF) { memset(cap,0,sizeof(cap)); memset(flow,0,sizeof(flow)); for(i=0;i<n;i++) { scanf("%d %d %d",&u,&v,&w); cap[u][v]+=w; } printf("%d\n",Edmonds_Karp(1)); } return 0;}