Dinic算法+各种优化最快速版本Acwing.2172:
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a) memset(a,0,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e5+5;
int n,m,S,T;
int head[maxn],d[maxn],cur[maxn],tot;
struct E{
int to,next,cap;
}edge[maxn<<1];
void add(int u,int v,int w){
edge[tot].to=v;
edge[tot].next=head[u];
edge[tot].cap=w;
head[u]=tot++;
}
bool bfs(){
memset(d,-1,sizeof(d));
queue<int> q;
q.push(S);d[S]=0;cur[S]=head[S];
while(!q.empty()){
int u=q.front();q.pop();
for(int i=head[u];i!=-1;i=edge[i].next){
int v=edge[i].to;
if(d[v]==-1&&edge[i].cap){
d[v]=d[u]+1;
cur[v]=head[v];
if(v==T) return true;
q.push(v);
}
}
}
return false;
}
int dfs(int u,int limit){
if(u==T) return limit;
int flow=0;
for(int i=cur[u];i!=-1&&flow<limit;i=edge[i].next){
cur[u]=i;
int v=edge[i].to;
if(d[v]==d[u]+1&&edge[i].cap){
int delta=dfs(v,min(edge[i].cap,limit-flow))