# 【BZOJ1934】善意的投票（网络流）

3 3

1 0 0

1 2

1 3

3 2

1

## 题解

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
using namespace std;
#define MAX 500
#define MAXL 200000
#define INF 20000000
{
int x=0,t=1;char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=-1,ch=getchar();
while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
return x*t;
}
struct Line
{
int v,next,w;
}e[MAXL];
int h[MAX],cnt;
int ans,S,T,n,m;
inline void Add(int u,int v,int w)
{
e[cnt]=(Line){v,h[u],w};
h[u]=cnt++;
e[cnt]=(Line){u,h[v],0};
h[v]=cnt++;
}
int level[MAX];
int cur[MAX];
bool BFS()
{
memset(level,0,sizeof(level));
level[S]=1;
queue<int> Q;
Q.push(S);
while(!Q.empty())
{
int u=Q.front();Q.pop();
for(int i=h[u];i!=-1;i=e[i].next)
{
int v=e[i].v;
if(e[i].w&&!level[v])
level[v]=level[u]+1,Q.push(v);
}
}
return level[T];
}
int DFS(int u,int flow)
{
if(flow==0||u==T)return flow;
int ret=0;
for(int &i=cur[u];i!=-1;i=e[i].next)
{
int v=e[i].v;
if(e[i].w&&level[v]==level[u]+1)
{
int dd=DFS(v,min(flow,e[i].w));
flow-=dd;ret+=dd;
e[i].w-=dd;e[i^1].w+=dd;
}
}
return ret;
}
int Dinic()
{
int ret=0;
while(BFS())
{
for(int i=S;i<=T;++i)cur[i]=h[i];
ret+=DFS(S,INF);
}
return ret;
}
int main()
{
memset(h,-1,sizeof(h));
S=0,T=n+1;
for(int i=1;i<=n;++i)
{