#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 Ford(int s,int t,int f)
{
if(s==t) return f;
for(int i=1;i<=m;i++)
{
if(vis[i] || g[s][i]==0) continue;
vis[i] = true;
int d = Ford(i,t,min(f,g[s][i]));
if(d>0)
{
g[s][i]-=d;
g[i][s]+=d;
return d;
}
}
return 0;
}
int find_flows(int s,int t)
{
int f = 0;
while(1)
{
memset(vis,0,sizeof(vis));
int flow = Ford(s,t,INF);
if(flow == 0) return f;
f+=flow;
}
}
int main()
{
int T, 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\n", find_flows(s,t));
return 0;
}
max_flow(Ford-Fulkerson)
最新推荐文章于 2024-08-28 09:15:00 发布