sqrt(3B) @ 2018-07-02 18:47:29
#include<bits/stdc++.h>
using namespace std;
#define maxb 210000
#define maxd 15000
#define INTM 2147400000
int n,m,s,t;
struct BBB{
int V,N,W;
}bian[maxb];
int Head[maxd],out=0;
void ADD(int u0,int v0,int w0)
{
bian[out].N=Head[u0];bian[out].W=w0;bian[out].V=v0;Head[u0]=out;out++;
bian[out].N=Head[v0];bian[out].W=0;bian[out].V=u0;Head[v0]=out;out++;
}
int DIS[maxd],q[maxd],tou=1,wei=1;
bool BF()
{
for(int i=0;i<maxd;++i){DIS[i]=-1;}
tou=1;wei=1;
q[1]=s;DIS[s]=0;
while(tou<=wei)
{
int _u=q[tou];tou++;
for(int i=Head[_u];i!=-1;i=bian[i].N)
{
int _v=bian[i].V,_w=bian[i].W;
if(DIS[_v]==-1&&_w)
{
wei++;q[wei]=_v;
DIS[_v]=DIS[_u]+1;//cout<<"!!!";
}
}
}
return DIS[t]^(-1);
}
int DF(int curd,int liu)
{
if(!(curd^t))return liu;
int used=0;
for(int i=Head[curd];i!=-1;i=bian[i].N)
{
int _V=bian[i].V,_W=bian[i].W;
if(DIS[_V]=DIS[curd]+1&&_W)
{
int k=DF(_V,min(liu-used,_W));
used+=k;
bian[i^1].W+=k;
bian[i].W-=k;
if(used==liu)break;
}
}
if(used==0)DIS[curd]=-1;
// cout<<" "<<used<<" ";
return used;
}
int main()
{
scanf("%d%d%d%d",&n,&m,&s,&t);
for(int i=1;i<=maxd;++i)Head[i]=-1;
int u,v,w;
for(int i=0;i<m;++i)
{
scanf("%d%d%d",&u,&v,&w);
ADD(u,v,w);
}//cout<<"~";
long long ans=0;
while(BF())
{//cout<<"!";
ans+=DF(s,INTM);//cout<<"@";
}//cout<<"#";
printf("%lld",ans);
return 0;
}