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

wc这不是和文理分科那啥一模一样嘛，还简单得多。。。

 //Twenty
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
const int maxn=20050,maxm=200050,INF=0x7f7f7f7f;
using namespace std;
int n,m,s,t,u,v,w,ecnt=1,fir[maxn],d[maxn],cur[maxn],c[maxn],p[maxn];
struct edge {
int from,to,cap,flow,nxt;
edge(){}
edge(int from,int to,int cap,int flow,int nxt):from(from),to(to),cap(cap),flow(flow),nxt(nxt){}
}e[maxm];
void add(int u,int v,int w) {
e[++ecnt]=edge(u,v,w,0,fir[u]);
e[++ecnt]=edge(v,u,0,0,fir[v]);
fir[u]=ecnt-1; fir[v]=ecnt;
}
queue<int>que;
void bfs(int s,int t) {
for(int i=1;i<=n;i++) d[i]=n;
d[t]=0;
que.push(t);
while(!que.empty()) {
int x=que.front() ;que.pop();
for(int i=fir[x];i;i=e[i].nxt)
if(d[e[i].to]==n&&e[i].flow==e[i].cap) {
d[e[i].to]=d[x]+1;
que.push(e[i].to);
}
}
}
int cal(int s,int t) {
int fl=INF;
for(int x=t;x!=s;x=e[p[x]].from)
fl=min(fl,e[p[x]].cap-e[p[x]].flow);
for(int x=t;x!=s;x=e[p[x]].from) {
e[p[x]].flow+=fl;
e[p[x]^1].flow-=fl;
}
return fl;
}
int maxflow(int s,int t) {
bfs(s,t);
int res=0;
for(int i=1;i<=n;i++) cur[i]=fir[i],c[d[i]]++;
for(int x=s;d[x]<n;) {
if(x==t) {
res+=cal(s,t);
x=s;
}
int ok=0;
for(int &i=cur[x];i;i=e[i].nxt)
if(d[e[i].to]+1==d[x]&&e[i].cap>e[i].flow){
p[x=e[i].to]=i;
ok=1; break;
}
if(!ok) {
cur[x]=fir[x]; int M=n;
for(int i=cur[x];i;i=e[i].nxt)
if(e[i].cap>e[i].flow)
M=min(M,d[e[i].to]+1);
if(!(--c[d[x]])) break;
c[d[x]=M]++;
if(x!=s) x=e[p[x]].from;
}
}
return res;
}
int main()
{
scanf("%d%d",&n,&m);
s=n+1; t=n+2;
for(int i=1;i<=n;i++) {
int x;
scanf("%d",&x);
}
n+=2;
for(int i=1;i<=m;i++) {
int x,y;
scanf("%d%d",&x,&y);
}