_stellar @ 2019-03-24 11:41:05
我哪里写错了吗..
感觉没任何问题啊
```
#include<bits/stdc++.h>
using namespace std;
#define N 1000004
int head[N],to[N],nxt[N],dis[N];
int dep[N];
int n,m,s,t;
int ans;
int cnt=-1;
void add(int u,int v,int w){
nxt[++cnt]=head[u];
head[u]=cnt;
to[cnt]=v;
dis[cnt]=w;
}
bool bfs(){
queue<int > q;
dep[s]=1;q.push(s);
while(!q.empty()){
int u=q.front();q.pop();
for(int i=head[u];i!=-1;i=nxt[i]){
int To=to[i];
if(!dep[To]&&dis[i]){
dep[To]=dep[u]+1;
q.push(To);
}
}
}
return (dep[t]!=0);
}
int dfs(int step,int ans){
if(step==t) return ans;
int flow=0;
for(int i=head[step];i!=-1;i=nxt[i]){
int To=to[i];
if(dep[To]==dep[step]+1&&dis[i]){
if(flow=(dfs(To,min(ans,dis[i])))){
dis[i]-=flow;
dis[i^1]+=flow;
return flow;
}
}
}
return 0;
}
const int INF=0x3f3f3f3f;
void dinic(){
ans=0;
while(bfs()){
while(int a=dfs(s,INF)) ans+=a;
}
}
int read(){
int x=0,w=0;
char ch=0;
while(!isdigit(ch)) w|=ch=='-',ch=getchar();
while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return w?-x:x;
}
int main(){
memset(head,-1,sizeof(head));
n=read(),m=read(),s=read(),t=read();
for(int i=1;i<=m;i++){
int a,b,c;
a=read(),b=read(),c=read();
add(a,b,c);add(b,a,0);
}
dinic();
printf("%d",ans);
printf("Time used:%.2f\n",(double)clock()/CLOCKS_PER_SEC);
return 0;
}
```