# BZOJ 1934: [Shoi2007]Vote 善意的投票

Time Limit: 1 Sec
Memory Limit: 64 MB

Description

Input

Output

Sample Input

3 3

1 0 0

1 2

1 3

3 2

Sample Output

1
HINT

#### Code####

#include<iostream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
{
int s=0,f=1;char ch=getchar();
while(!('0'<=ch&&ch<='9')){if(ch=='-')f=-1;ch=getchar();}
while('0'<=ch&&ch<='9'){s=(s<<3)+(s<<1)+ch-'0';ch=getchar();}
return s*f;
}
int S,T,n,m,np;
int A[305];
int be[100005],bn[200005],bv[200005],bl[200005],bw=1;
void put(int u,int v,int l)
{bw++;bn[bw]=be[u];be[u]=bw;bv[bw]=v;bl[bw]=l;}
int d[100005];
bool spfa(int S,int T)
{
for(int i=1;i<=np;i++)
d[i]=10000000;
d[S]=1;
queue<int>q;
for(q.push(S);!q.empty();)
{int u=q.front();q.pop();
for(int i=be[u],v;i;i=bn[i])
if(d[v=bv[i]]>d[u]+1&&bl[i])
{d[v]=d[u]+1;
q.push(v);
}
}
return d[T]!=10000000;
}
int ans;
int dinic(int u,int mf,int T)
{
if(mf==0)return 0;
if(u==T)return mf;
int sum=0;
for(int i=be[u],v;i;i=bn[i])
if(d[v=bv[i]]==d[u]+1)
{int f=dinic(v,min(mf-sum,bl[i]),T);
bl[i]-=f;
bl[i^1]+=f;
sum+=f;
}
return sum;
}
int main()
{
S=++np,T=++np;
for(int i=1;i<=n;i++)
{A[i]=++np;
put(S,A[i],1),
put(A[i],S,0);
else
put(A[i],T,1),
put(T,A[i],0);
}
for(int i=1;i<=m;i++)