# 最小投票BZOJ 1934([Shoi2007]Vote 善意的投票-最小割)

## 1934: [Shoi2007]Vote 好心的投票

Time Limit:

1 Sec

Memory Limit:

64 MB

Submit:

612

Solved:

365

[

][

][

]

3 3
1 0 0
1 2
1 3
3 2

1

## Source

每日一道理

[

][

][

]

想到是最小割就好办了呢。。。。（喂我没想到啊混蛋）

S向赞同的小孩连，T向反对的连，挚友互相连，容量皆为1

OK（根据最小割定义,最小割切的都是从S向T的有向边【话外：反向呢？答:疏忽】，明显成立）

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (300+2+10)
#define MAXM (MAXN*MAXN*4)
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
int edge[MAXM],pre[MAXN]={0},next[MAXM],weight[MAXM],size=1;
{
edge[++size]=v;
weight[size]=w;
next[size]=pre[u];
pre[u]=size;
}
int d[MAXN]={0},cnt[MAXN]={0},s,t;
int totflow=0;
int sap(int x,int flow)
{
if (x==t) return flow;
int nowflow=0;
Forp(x)
{
int &v=edge[p];
if (d[v]==d[x]-1&&weight[p]>0)
{
int fl=sap(v,min(flow,weight[p]));
weight[p]-=fl,weight[p^1]+=fl,flow-=fl,nowflow+=fl;
if (!flow) return nowflow;
}
}
if (!(--cnt[d[x]++])) d[s]=t+1;
cnt[d[x]]++;
return nowflow;
}
int n,m,a[MAXN];
int main()
{
//	freopen("conflict.in","r",stdin);
//	freopen("conflict.out","w",stdout);
scanf("%d%d",&n,&m);
s=n+1,t=s+1;
For(i,n)
{
scanf("%d",&a[i]);
}
For(i,m)
{
int u,v;
scanf("%d%d",&u,&v);
}
cnt[0]=n+2;
while (d[s]<=t) totflow+=sap(s,INF);
cout<<totflow<<endl;

return 0;
}

--------------------------------- 原创文章 By

---------------------------------

posted @ 2013-06-22 22:35  xinyuyuanm  阅读(194)  评论(0编辑  收藏