复杂度O(V2E)O(V^2E)O(V2E)
const int maxn=2e3+100;
const int INF=0x3f3f3f3f;
ll n,m,tol,head[maxn];
struct edge{
ll to,next,w;
}a[maxn*10];
void init(){
memset(head,-1,sizeof head);
tol=1;
}
inline void add(ll u,ll v,ll w){
a[++tol]=(edge){v,head[u],w};head[u]=tol;
a[++tol]=(edge){u,head[v],0};head[v]=tol;
}
ll dep[10010],cur[10010];
queue<ll>q;
ll bfs(ll s,ll t){
ll i,u,v;
for(i=s;i<=t;i++) dep[i]=-1,cur[i]=head[i];
q.push(s);dep[s]=0;
while(!q.empty()){
u=q.front();q.pop();
for(i=head[u];~i;i=a[i].next){
v=a[i].to;if(~dep[v]||!a[i].w) continue;
dep[v]=dep[u]+1;q.push(v);
}
}
return ~dep[t];
}
ll dfs(ll u,ll t,ll lim){
if(u==t||!lim) return lim;
ll i,v,f,flow=0;
for(i=cur[u];~i;i=a[i].next){
v=a[i].to;cur[u]=i;
if((dep[v]==dep[u]+1)&&(f=dfs(v,t,min(lim,a[i].w)))){
a[i].w-=f;a[i^1].w+=f;
flow+=f;lim-=f;
if(!lim) return flow;
}
}
return flow;
}
ll dinic(ll s,ll t){
ll re=0;
while(bfs(s,t)) re+=dfs(s,t,INF);
return re;
}