Konnyaku_LXZ @ 2021-04-07 08:49:51
蒟蒻反向边没加都 A 了。
Code:
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<cmath>
using namespace std;
typedef long long LL;
const LL MAXN=505,MAXM=1e4+50,INF=0x3f3f3f3f3f3f3f3f;
struct edge{
LL nxt;
LL to;
LL cap;
LL flow;
};
LL N,M,s,t,dis[MAXN],Ans=0;
edge e[MAXM<<1];
LL head[MAXN],now[MAXN],Cnte=1;
queue<LL> q;
void adde(LL u,LL v,LL w){
++Cnte;
e[Cnte].to=v;
e[Cnte].cap=w;
e[Cnte].nxt=head[u];
head[u]=Cnte;
}
bool bfs(){
for(int i=1;i<=N;++i) dis[i]=INF;
while(!q.empty()) q.pop();
q.push(s);
dis[s]=0;
while(!q.empty()){
LL u=q.front();
q.pop();
now[u]=head[u];
for(int i=head[u];i;i=e[i].nxt){
LL v=e[i].to;
if(e[i].cap>e[i].flow&&dis[u]+1<dis[v]){
dis[v]=dis[u]+1;
q.push(v);
}
}
}
return dis[t]!=INF;
}
LL dfs(LL u,LL flow){
if(flow==0||u==t) return flow;
LL res=0;
for(int i=now[u];i;i=e[i].nxt){
now[u]=i;
LL v=e[i].to;
if(dis[v]==dis[u]+1&&e[i].cap>e[i].flow){
LL t=dfs(v,min(e[i].cap-e[i].flow,flow));
if(!t) continue;
e[i].flow+=t;
//e[i^1].flow-=t;
res+=t;
flow-=t;
if(flow==0) break;
}
}
if(res==0) dis[u]=INF;
return res;
}
LL Dinic(){
LL res=0;
while(bfs()) res+=dfs(s,INF);
return res;
}
void Init(){
scanf("%lld%lld%lld%lld",&N,&M,&s,&t);
for(int i=1;i<=M;++i){
LL u,v,w;
scanf("%lld%lld%lld",&u,&v,&w);
adde(u,v,w);//adde(v,u,0);
}
}
void Solve(){
Ans=Dinic();
}
void Print(){
printf("%lld\n",Ans);
}
int main(){
Init();
Solve();
Print();
return 0;
}
by 18Michael @ 2021-04-07 08:50:41
Orz
by Konnyaku_LXZ @ 2021-04-07 08:50:56
提交链接:
https://www.luogu.com.cn/record/49093361
by lytqwq @ 2021-04-07 08:54:16
Orz
by Drystynt @ 2021-04-07 09:49:27
Orz
by ctt2006 @ 2021-04-07 10:14:10
Orz
by ducati @ 2021-04-07 11:04:12
我的天哪
by ducati @ 2021-04-07 11:04:22
Orz Orz Orz
by lcc17 @ 2021-04-07 20:38:22
Orz