h_rains @ 2023-02-26 20:51:47
RT
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1010,maxm=20010,INF=0x3f3f3f3f;
int n,m,S,T;
int h[maxn],e[maxm],f[maxm],ne[maxm],idx;
int q[maxn],d[maxn],pre[maxn];
bool st[maxn];
void add(int u,int v,int w)
{
e[idx]=v,f[idx]=w,ne[idx]=h[u],h[u]=idx++;
e[idx]=u,f[idx]=w,ne[idx]=h[v],h[v]=idx++;
}
bool bfs()
{
int hh=0,tt=0;
memset(st,false,sizeof(st));
q[0]=S,st[S]=true,d[S]=INF;
while(hh<=tt)
{
int t=q[hh++];
for(int i=h[t];~i;i=ne[i])
{
int v=e[i];
if(!st[v]&&f[i])
{
st[v]=1;
d[v]=min(d[t],f[i]);
pre[v]=i;
if(v==T) return 1;
q[++tt]=v;
}
}
}
return 0;
}
int EK()
{
int ans=0;
while(bfs())
{
ans+=d[T];
for(int i=T;i!=S;i=e[pre[i]^1]) f[pre[i]]-=d[T],f[pre[i]^1]+=d[T];
}
return ans;
}
signed main()
{
cin>>n>>m>>S>>T;
memset(h,-1,sizeof(h));
while(m--)
{
int u,v,w;
cin>>u>>v>>w;
add(u,v,w);
}
cout<<EK()<<endl;
}
只能过后3个点其余全WA/ll
by Mikefeng @ 2023-02-27 07:44:13
但是不会EK
by h_rains @ 2023-03-27 18:13:01
破案啦!加边的时候第二行f[idx]=0