# BZOJ1934：[SHOI2007]善意的投票 & BZOJ2768：[JLOI2010]冠军调查——题解

https://www.lydsy.com/JudgeOnline/problem.php?id=1934

https://www.lydsy.com/JudgeOnline/problem.php?id=2768

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cctype>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const int N=350;
const int M=N*N+N;
const int INF=1e9;
int X=0,w=0;char ch=0;
while(!isdigit(ch)){w|=ch=='-';ch=getchar();}
while(isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
return w?-X:X;
}
struct node{
int nxt,to,w;
}edge[M];
}
int lev[N],cur[N],dui[N];
bool bfs(int m){
int r=0;
for(int i=1;i<=m;i++){
lev[i]=-1;
}
dui[0]=S,lev[S]=0;
int u,v;
for(int l=0;l<=r;l++){
u=dui[l];
v=edge[e].to;
if(edge[e].w>0&&lev[v]==-1){
lev[v]=lev[u]+1;
r++;
dui[r]=v;
if(v==T)return 1;
}
}
}
return 0;
}
int dinic(int u,int flow,int m){
if(u==m)return flow;
int res=0,delta;
for(int &e=cur[u];e!=-1;e=edge[e].nxt){
int v=edge[e].to;
if(edge[e].w>0&&lev[u]<lev[v]){
delta=dinic(v,min(edge[e].w,flow-res),m);
if(delta>0){
edge[e].w-=delta;
edge[e^1].w+=delta;
res+=delta;
if(res==flow)break;
}
}
}
if(res!=flow)lev[u]=-1;
return res;
}
int c[N];
int main(){
S=n+1,T=S+1;
for(int i=1;i<=n;i++){
}
for(int i=1;i<=m;i++){
if(c[b])swap(a,b);
}
int ans=0;
while(bfs(T))ans+=dinic(S,INF,T);
printf("%d\n",ans);
return 0;
}

+++++++++++++++++++++++++++++++++++++++++++

+本文作者：luyouqi233。 　　　　　　　　　　　　　　+

+欢迎访问我的博客：http://www.cnblogs.com/luyouqi233/ +

+++++++++++++++++++++++++++++++++++++++++++

posted @ 2018-05-19 15:34  luyouqi233  阅读(149)  评论(0编辑  收藏