hhhh赛前自己写了一个版本的模板,也不知道效率咋样,但是亲手写出来的意义不同!嗯!
#include<bits/stdc++.h>
using namespace std;
#define INF (1e18)
typedef long long ll;
const ll maxn=205,maxm=50205;
ll n,m,S,T,sum,cnt;
ll l[maxm],head[maxn];//注意l是maxm
struct node{
ll to,ne,w;
}e[maxm];
void add(ll u,ll v,ll w){
e[cnt]=(node){v,head[u],w};head[u]=cnt++;
e[cnt]=(node){u,head[v],0};head[v]=cnt++;
}
queue<ll>q;
ll d[maxn],cur[maxn];
ll bfs(){
while(!q.empty()) q.pop();
memset(d,0,sizeof(d));
memcpy(cur,head,sizeof(head));
d[S]=1;q.push(S);
while(!q.empty()){
ll u=q.front();q.pop();
if(u==T) break;
for(ll i=head[u];~i;i=e[i].ne){
ll v=e[i].to;
if(!e[i].w) continue;
if(!d[v]) d[v]=d[u]+1,q.push(v);
}
}
return d[T];
}
ll dfs(ll u,ll remain){
if(u==T) return remain;
ll use=0;
for(ll &i=cur[u];~i;i=e[i].ne){
ll v=e[i].to;
if(e[i].w&&remain&&d[v]==d[u]+1){
ll flow=dfs(v,min(remain-use,e[i].w));
if(!flow) continue;
use+=flow;e[i].w-=flow;e[i^1].w+=flow;
if(use==remain) break;
}
}
if(!use) d[u]=-1;
return use;
}
ll dinic(){
ll ans=0,tmp;
while(bfs()){
while(tmp=dfs(S,INF)) ans+=tmp;
}
return ans;
}
void getmap(){}
int main(){
while(~scanf("%lld%lld",&n,&m)){
cnt=0;
memset(head,-1,sizeof(head));
S=n+1;T=S+1;
getmap();
ll ans=dinic();
}
return 0;
}