#include <cstdio> #include <iostream> #include <cstring> #include<queue> using namespace std; const int INF = 0x3fffffff; int g[1005][1005]; bool vis[1005]; int m; int Edmond_Karp(int s,int t) { int pre[1005]; int flow[1005]; memset(pre,0,sizeof(pre)); for(int i=0;i<=m;i++) flow[i] = INF; queue<int>q; q.push(s); while(q.size()) { int v = q.front(); q.pop(); for(int i=1;i<=m;i++) { if(pre[i] || i==v || g[v][i]==0) continue; pre[i] = v; flow[i] = min(flow[v],g[v][i]); if(i==t) { for(int j=t;j!=s;j=pre[j]) { g[pre[j]][j]-=flow[t]; g[j][pre[j]]+=flow[t]; } return flow[t]; } q.push(i); } } return 0; } int find_flows(int s,int t) { int f = 0; while(1) { memset(vis,0,sizeof(vis)); int flow = Edmond_Karp(s,t); if(flow == 0) return f; f+=flow; } } int main() { int a, b, len; int s, t, p; scanf("%d%d", &m, &p); scanf("%d%d",&s,&t); memset(g,0,sizeof(g)); while(p--) { scanf("%d%d%d", &a, &b, &len); g[a][b] += len; } printf("%d ", find_flows(s,t)); return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。