# BZOJ1934: [Shoi2007]Vote 善意的投票

BZOJ1934: [Shoi2007]Vote 善意的投票

3 3
1 0 0
1 2
1 3
3 2

1

## 题解Here!

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#define MAXN 310
#define MAXM 200010
#define MAX 999999999
using namespace std;
int n,m,s,t,c=2;
struct Edge{
int next,to,w;
}a[MAXM];
int date=0,w=1;char c=0;
while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
while(c>='0'&&c<='9'){date=date*10+c-'0';c=getchar();}
return date*w;
}
inline void add(int u,int v,int w){
}
bool bfs(){
int u,v;
queue<int> q;
for(int i=1;i<=t;i++)deep[i]=0;
deep[s]=1;
q.push(s);
while(!q.empty()){
u=q.front();
q.pop();
v=a[i].to;
if(a[i].w&&!deep[v]){
deep[v]=deep[u]+1;
if(v==t)return true;
q.push(v);
}
}
}
return false;
}
int dfs(int x,int limit){
if(x==t)return limit;
int v,sum,cost=0;
v=a[i].to;
if(a[i].w&&deep[v]==deep[x]+1){
sum=dfs(v,min(a[i].w,limit-cost));
if(sum>0){
a[i].w-=sum;
a[i^1].w+=sum;
cost+=sum;
if(cost==limit)break;
}
else deep[v]=-1;
}
}
return cost;
}
int dinic(){
int ans=0;
while(bfs())ans+=dfs(s,MAX);
return ans;
}
void init(){
int x,y;
s=n+1;t=n+2;
for(int i=1;i<=n;i++){
}
for(int i=1;i<=m;i++){