qscqesze
Published on 2017-09-02 11:31 in 暂未分类 with qscqesze

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

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

Time Limit: 1 Sec

Memory Limit: 256 MB

## 题目连接

http://www.lydsy.com/JudgeOnline/problem.php?id=1934

3 3
1 0 0
1 2
1 3
3 2

1

## HINT

S连同意的，T连不同意的

#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
using namespace std;
const int Ni = 100210;
const int MAX = 1<<26;
struct Edge{
int u,v,c;
int next;
}edge[20*Ni];
int n,m;
int edn;//边数
int p[Ni];//父亲
int d[Ni];
int sp,tp;//原点，汇点

{
edge[edn].u=u; edge[edn].v=v; edge[edn].c=c;
edge[edn].next=p[u]; p[u]=edn++;

edge[edn].u=v; edge[edn].v=u; edge[edn].c=0;
edge[edn].next=p[v]; p[v]=edn++;
}
int bfs()
{
queue <int> q;
memset(d,-1,sizeof(d));
d[sp]=0;
q.push(sp);
while(!q.empty())
{
int cur=q.front();
q.pop();
for(int i=p[cur];i!=-1;i=edge[i].next)
{
int u=edge[i].v;
if(d[u]==-1 && edge[i].c>0)
{
d[u]=d[cur]+1;
q.push(u);
}
}
}
return d[tp] != -1;
}
int dfs(int a,int b)
{
int r=0;
if(a==tp)return b;
for(int i=p[a];i!=-1 && r<b;i=edge[i].next)
{
int u=edge[i].v;
if(edge[i].c>0 && d[u]==d[a]+1)
{
int x=min(edge[i].c,b-r);
x=dfs(u,x);
r+=x;
edge[i].c-=x;
edge[i^1].c+=x;
}
}
if(!r)d[a]=-2;
return r;
}

int dinic(int sp,int tp)
{
int total=0,t;
while(bfs())
{
while(t=dfs(sp,MAX))
total+=t;
}
}
int main()
{
int i,u,v,c;
while(~scanf("%d%d",&n,&m))
{
edn=0;//初始化
memset(p,-1,sizeof(p));
sp=0;tp=n+1;
for(int i=1;i<=n;i++)
{
int x;
scanf("%d",&x);
}
for(int i=1;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
}