optimize_2 @ 2020-08-08 13:40:03
RT
#include<bits/stdc++.h>
using namespace std;
int n,m,s,t,cnt=1,first[10010],nxt[200010],to[200010],w[200010];
bool vst[100010];
void add(int u,int v,int w2) {
cnt++;
w[cnt]=w2;
to[cnt]=v;
nxt[cnt]=first[u];
first[u]=cnt;
}
int dep[10010];
bool bfs() {
memset(dep,0,sizeof(dep));
queue<int>q;
q.push(1);
dep[s]=1;
while(!q.empty()) {
int head=q.front();
q.pop();
for(int e=first[head];e;e=nxt[e]) {
int v=to[e];
if(!dep[v]&&w[e]) {
dep[v]=dep[head]+1;
q.push(v);
}
}
}
return dep[t];
}
int dinic(int now,int flow) {
if(now==t) {
return flow;
}
int out=0;
for(int e=first[now];e&&flow;e=nxt[e]) {
int v=to[e];
if((dep[v]==dep[now]+1)&&(w[e])) {
int outnow=dinic(v,min(w[e],flow));
flow-=outnow;
w[e]-=outnow;
w[e^1]+=outnow;
out+=outnow;
}
}
if(out==0) dep[now]=0;
return out;
}
int main() {
int ans=0;
cin>>n>>m>>s>>t;
for(int i=1;i<=m;i++) {
int u2,v2,w2;
cin>>u2>>v2>>w2;
add(u2,v2,w2);
add(v2,u2,0);
}
while(bfs()) {
ans+=dinic(s,2e9);
}
cout<<ans;
}
by Dimly_dust @ 2020-08-08 13:41:37
btd,jbl
by 博瀚君 @ 2020-08-08 13:49:14
《关于一句很长的句子加一对书名号就能变成日漫这档事》
by 绝顶我为峰 @ 2020-08-08 13:50:23
《关于书名号滥用这档事》
by wwhOvO @ 2020-08-08 13:59:51
《关于书名号滥用这档事》
by fjdkfhjd @ 2020-08-08 14:20:27
《关于书名号滥用这档事》
by grass8cow @ 2020-08-08 14:22:12
《关于书名号滥用这档事》
by Earthcomputer @ 2020-08-08 20:59:08
《关于书名号滥用这档事》
by optimize_2 @ 2020-08-08 21:00:04
@М652 az
by 辰星凌 @ 2020-08-08 21:06:17
又一个没挂当前狐的?
by Belarus @ 2020-08-08 21:07:27
if((dep[v]==dep[now]+1)&&(w[e])) {
int outnow=dinic(v,min(w[e],flow));
flow-=outnow;
w[e]-=outnow;
w[e^1]+=outnow;
out+=outnow;
}
->
if((dep[v]==dep[now]+1)&&(w[e])&&out<flow) {
int outnow=dinic(v,min(w[e],flow-out));
w[e]-=outnow;
w[e^1]+=outnow;
out+=outnow;
}
试试