#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn = 100100, INF = 0x7fffffff;
int d[maxn], head[maxn];
int n, m, s, t;
struct edge{
int u, v, f, c, next;
}Node[2*maxn];
void add(int u, int v, int c, int f, int i)
{
Node[i].u = u;
Node[i].v = v;
Node[i].f = f;
Node[i].c = c;
Node[i].next = head[u];
head[u] = i;
}
int bfs()
{
queue<int> Q;
mem(d,0);
Q.push(s);
d[s] = 1;
while(!Q.empty()){
int u = Q.front(); Q.pop();
for(int i=head[u]; i!=-1; i=Node[i].next)
{
edge e = Node[i];
if(!d[e.v] && e.c > e.f)
{
d[e.v] = d[e.u] + 1;
Q.push(e.v);
}
}
}
return d[t] != 0;
}
int dfs(int u, int cap)
{
// cout<< u << " " << cap <<endl;
if(u == t)
return cap;
for(int i=head[u]; i!= -1; i=Node[i].next)
{
edge e = Node[i];
if(d[e.v] == d[e.u] + 1 && e.c > e.f)
{
int V = dfs(e.v, min(cap, e.c - e.f));
if(V > 0){
Node[i].f += V;
Node[i^1].f -= V;
return V;
}
}
}
return 0;
}
int Dinic()
{
int ans = 0;
while(bfs())
{
while(int l = dfs(s,INF))
ans += l;
}
return ans;
}
int main()
{
mem(head,-1);
cin>> n >> m >> s >> t;
int cnt = 0;
for(int i=0; i<m; i++)
{
int u, v, w;
cin>> u >> v >> w;
add(u, v, w, 0, cnt++);
add(v, u, 0, 0, cnt++);
}
cout<< Dinic() <<endl;
return 0;
}
自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。