BZOJ 1934([Shoi2007]Vote 善意的投票-最小割)
2013-06-23 16:55:00      个评论

[Submit][Status][Discuss]
Description

Input

Output

Sample Input
3 3
1 0 0
1 2
1 3
3 2

Sample Output
1
HINT

Source
Day2

[Submit][Status][Discuss]
﻿想到是最小割就好办了呢。。。。（喂我没想到啊混蛋）

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

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

[cpp]  #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;

#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;
}