# 【刷题】BZOJ 1934 [Shoi2007]Vote 善意的投票

3 3
1 0 0
1 2
1 3
3 2

1

## Solution

#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
const int MAXN=300+10,MAXM=MAXN*MAXN+10,inf=0x3f3f3f3f;
int n,m,e=1,beg[MAXN],cur[MAXN],level[MAXN],vis[MAXN],clk,s,t,to[MAXM<<1],nex[MAXM<<1],cap[MAXM<<1];
std::queue<int> q;
template<typename T> inline void read(T &x)
{
T data=0,w=1;
char ch=0;
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')w=-1,ch=getchar();
while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
if(ch!='\0')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
inline void insert(int x,int y,int z)
{
to[++e]=y;
nex[e]=beg[x];
beg[x]=e;
cap[e]=z;
to[++e]=x;
nex[e]=beg[y];
beg[y]=e;
cap[e]=0;
}
inline bool bfs()
{
memset(level,0,sizeof(level));
level[s]=1;
q.push(s);
while(!q.empty())
{
int x=q.front();
q.pop();
for(register int i=beg[x];i;i=nex[i])
if(cap[i]&&!level[to[i]])level[to[i]]=level[x]+1,q.push(to[i]);
}
return level[t];
}
inline int dfs(int x,int maxflow)
{
if(x==t||!maxflow)return maxflow;
vis[x]=clk;
int res=0;
for(register int &i=cur[x];i;i=nex[i])
if((vis[x]^vis[to[i]])&&cap[i]&&level[to[i]]==level[x]+1)
{
int f=dfs(to[i],min(cap[i],maxflow));
res+=f;
cap[i]-=f;
cap[i^1]+=f;
maxflow-=f;
if(!maxflow)break;
}
return res;
}
inline int Dinic()
{
int res=0;
while(bfs())clk++,memcpy(cur,beg,sizeof(cur)),res+=dfs(s,inf);
return res;
}
int main()
{
s=n+1,t=s+1;
for(register int i=1;i<=n;++i)
{