sycqwq @ 2022-01-24 23:10:07
rt
#include<bits/stdc++.h>
#define int long long
#define inf LLong_MAX
using namespace std;
const int maxn=20005,maxm=500005;
int n,m,s,t,tot=1,head[maxn],de[maxn];
struct node
{
int v,nxt,w;
}e[maxm<<1];
void add(int x,int y,int w)
{
e[++tot].v=y;
e[tot].nxt=head[x];
head[x]=tot;
e[tot].w=w;
}
queue<int> q;
int bfs()
{
while(!q.empty())
q.pop();
q.push(s);
memset(de,0,sizeof de);
de[s]=1;
// cout<<"QWQ"<<endl;
while(!q.empty())
{
int x=q.front();
// cout<<x<<endl;
q.pop();
for(int i=head[x];i;i=e[i].nxt)
{
int v=e[i].v;
if(de[v]||!e[i].w)
continue;
q.push(v);
de[v]=de[x]+1;
}
}
// cout<<"OK"<<' '<<de[t]<<endl;
return de[t];
}
// int ans;
int ans=0;
int dfs(int u,int x)
{
if(u==t)
return x;
int s=0;
// cout<<x<<endl;
for(int i=head[u];i&&x;i=e[i].nxt)
{
// cout<<"QWQ"<<endl;
int v=e[i].v;
// cout<<v<<endl;
// cout<<ans<<' '<<v<<' '<<de[v]<<' '<<de[u]<<endl;
if(e[i].w&&de[v]==de[u]+1)
{
// cout<<"QWQ"<<endl;
// cout<<"OK"<<endl;
int res=dfs(v,min(x,e[i].w));
// cout<<"QWQ"<<endl;
e[i].w-=res;
e[i^1].w+=res;
x-=res;
s+=res;
// cout<<u<<' '<<v<<' '<<res<<' '<<s<<endl;
}
}
if(s==0)
de[x]=0;
return s;
}
signed main()
{
cin>>n>>m>>s>>t;
for(int i=1;i<=m;i++)
{
int u,v,w;
cin>>u>>v>>w;
add(u,v,w);
add(v,u,0);
}
while(bfs())
{
// cout<<"QWQ"<<endl;
ans+=dfs(s,192608171926081 );
// cout<<ans<<endl;
}
cout<<ans;
return 0;
}
by hrgd @ 2022-01-24 23:14:52
你试试 192608171926081ll
by sycqwq @ 2022-01-24 23:17:18
@hrgd 没用
by hrgd @ 2022-01-24 23:18:48
@无敌的蒟蒻 那你这个没毛问题
by 约瑟夫用脑玩 @ 2022-01-24 23:21:44
@无敌的蒟蒻 71,72 行的问题
by 约瑟夫用脑玩 @ 2022-01-24 23:22:22
比如改成这样就不会挂了:
int dfs(int u,int x)
{
if(u==t)
return x;
int sm=0;
// cout<<x<<endl;
for(int i=head[u];i&&x;i=e[i].nxt)
{
// cout<<"QWQ"<<endl;
int v=e[i].v;
// cout<<v<<endl;
// cout<<ans<<' '<<v<<' '<<de[v]<<' '<<de[u]<<endl;
if(e[i].w&&de[v]==de[u]+1)
{
// cout<<"QWQ"<<endl;
// cout<<"OK"<<endl;
int res=dfs(v,min(x,e[i].w));
if(!res)
{
de[v]=0;
continue;
}
// cout<<"QWQ"<<endl;
e[i].w-=res;
e[i^1].w+=res;
x-=res;
sm+=res;
// cout<<u<<' '<<v<<' '<<res<<' '<<s<<endl;
}
}
return sm;
}
by sycqwq @ 2022-01-24 23:22:26
@约瑟夫用脑玩 草,谢谢
by sycqwq @ 2022-01-24 23:22:48
@约瑟夫用脑玩 我v打成x了
by sycqwq @ 2022-01-24 23:23:02
哦不是u打成x了
by 约瑟夫用脑玩 @ 2022-01-24 23:23:51
函数传(int x,int y,int z)
保平安(bushi