1934: [Shoi2007]Vote 善意的投票

题目:传送门

题解:

   明显的不能再明显的最小割。。。

   st连同意的,不同意的连ed

  朋友之间两两连边(即双向边)

   流量都为1...

   为啥:

   一个人只有两种选择...同意or不同意

   那么如果选择违背了个人意愿那么肯定要割掉一条边(起冲突了嘛),那就是流量啊...

   如果当前选择让两个盆友不在同一集合,那就产生了冲突,还是要割,还是流量啊...

   一A美滋滋~

代码水一发:

 #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define qread(x) x=read()
using namespace std;
inline int read()
{
int f=,x=;char ch;
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return f*x;
}
struct node
{
int x,y,c,next,other;
}a[];int len,last[];
int n,m,st,ed;
void ins(int x,int y,int c)
{
int k1,k2;
k1=++len;
a[len].x=x;a[len].y=y;a[len].c=c;
a[len].next=last[x];last[x]=len; k2=++len;
a[len].x=y;a[len].y=x;a[len].c=;
a[len].next=last[y];last[y]=len; a[k1].other=k2;
a[k2].other=k1;
}
int list[],h[],head,tail;
bool bt_h()
{
memset(h,,sizeof(h));h[st]=;
list[]=st;head=;tail=;
while(head!=tail)
{
int x=list[head];
for(int k=last[x];k;k=a[k].next)
{
int y=a[k].y;
if(h[y]== && a[k].c>)
{
h[y]=h[x]+;
list[tail++]=y;
}
}
head++;
}
if(h[ed]>)return true;
return false;
}
int find_flow(int x,int flow)
{
if(x==ed)return flow;
int s=,t;
for(int k=last[x];k;k=a[k].next)
{
int y=a[k].y;
if(h[y]==h[x]+ && a[k].c> && s<flow)
{
s+=t=find_flow(y,min(a[k].c,flow-s));
a[k].c-=t;a[a[k].other].c+=t;
}
}
if(s==)h[x]=;
return s;
}
int main()
{
qread(n);qread(m);
len=;memset(last,,sizeof(last));
st=-;ed=st+;
for(int i=;i<=n;i++)
{
int x;qread(x);
if(x==)ins(st,i,);
else ins(i,ed,);
}
for(int i=;i<=m;i++)
{
int x,y;
qread(x);qread(y);
ins(x,y,);
ins(y,x,);
}
int ans=;
while(bt_h())ans+=find_flow(st,);
printf("%d\n",ans);
return ;
}

bzoj1934: [Shoi2007]Vote 善意的投票(显然最小割)的更多相关文章

  1. BZOJ1934 [Shoi2007]Vote 善意的投票 【最小割】

    题目 幼儿园里有n个小朋友打算通过投票来决定睡不睡午觉.对他们来说,这个问题并不是很重要,于是他们决定发扬谦让精神.虽然每个人都有自己的主见,但是为了照顾一下自己朋友的想法,他们也可以投和自己本来意愿 ...

  2. bzoj1934: [Shoi2007]Vote 善意的投票(最小割)

    传送门 考虑源点为同意,汇点为反对,那么只要源点向同意的连边,不同意的向汇点连边,求个最小割就是答案 然后考虑朋友之间怎么办,我们令朋友之间连双向边.这样不管怎么割都能对应一种选择情况.那么还是求一个 ...

  3. [BZOJ1934][SHOI2007]Vote 善意的投票:最小割

    分析 先讲一下连边方法: \(S\)向意愿同意的人,意愿反对的人向\(T\),朋友之间互相连(其实好像意愿不同的朋友之间互相连就可以了,嘛,不管了),容量均为\(1\). 最小割即为答案. 可以理解为 ...

  4. [bzoj1934/2768][Shoi2007]Vote 善意的投票_最小割

    Vote 善意的投票 bzoj-1934 Shoi-2007 题目大意:题目链接. 注释:略. 想法: 这是最小割的一个比较基本的模型. 我们将所有当前同意的小朋友连向源点,边权为1.不容易的连向汇点 ...

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

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1934 [题目大意] 每个人对于投票都有自己原来的观点:1或者0, 他可以违背自己原来的 ...

  6. 2018.10.13 bzo1934: [Shoi2007]Vote 善意的投票(最小割)

    传送门 最小割定义题. 按照题意建边就行了. 考虑把冲突变成把aaa选入不与自己匹配的集合所需要付出的代价. 然后跑最小割就行了. 代码: #include<bits/stdc++.h> ...

  7. bzoj 1934: [Shoi2007]Vote 善意的投票 (最小割)

    原来是赞同的连源,原来是反对的连汇,然后是朋友的就连在一起,这样最小割就是割掉违背和谐的吧 type arr=record toward,next,cap:longint; end; const ma ...

  8. bzoj1934: [Shoi2007]Vote 善意的投票

    最大流..建图方式都是玄学啊.. //Dinic是O(n2m)的. #include<cstdio> #include<cstring> #include<cctype& ...

  9. bzoj1934: [Shoi2007]Vote 善意的投票&&bzoj2768:[JLOI2010]冠军调查

    get到新姿势,最小割=最大流,来个大佬的PPT 这道题的做法是将st和1的xpy连,0的xpy和ed连,xpy之间jy连双向边,然后呢答案就是最小割. #include<cstdio> ...

随机推荐

  1. maven常用插件功能

    maven-dependency-plugin http://maven.apache.org/plugins/maven-dependency-plugin/ maven-dependency-pl ...

  2. WCF 无法激活服务,由于它不支持 ASP.NET 兼容性。已为此应用程序启用了 ASP.NET 兼容性

    作者:jiankunking 出处:http://blog.csdn.net/jiankunking 错误信息: 无法激活服务.由于它不支持 ASP.NET 兼容性.已为此应用程序启用了 ASP.NE ...

  3. Microsoft Updateclient更新

     大家好, 微软Microsoft Update产品组官方博客于昨天宣布了有关最新的Windows Updateclient更新的消息.依据这则博客.微软从当日開始逐渐向全部Windows 7, ...

  4. Vitual Router in The Cloud

    VyOS and ESXi,VyOS Configuration The next step is to configure both VyOS routers. Before we do, we s ...

  5. poj1961--Period(KMP求最小循环节)

    Period Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 13511   Accepted: 6368 Descripti ...

  6. 去除iframe滚动条1

    主页面的IFRAME中添加:scrolling="yes" 子页面程序代码: 让竖条消失: <body style='overflow:scroll;overflow-x:a ...

  7. MVC开发模式详解

    转自:https://blog.csdn.net/qq_33991989/article/details/78966071 MVC设计模式详解 1.Model-View-Controller(模型-视 ...

  8. 时间处理工具类TimeUtil

    转自:https://cnblogs.com/ityouknow/p/5662753.html 功能 Date与String之间的互相转换,以及一些特殊格式的时间字符串处理 代码 /** * 类名:T ...

  9. jqGrid的editrules参数

    原文链接:http://blog.csdn.net/mengtianyalll/article/details/13502841 editrules    editrules是用来设置一些可用于可编辑 ...

  10. C# 对象初始化器和集合初始化器

    /// <summary>/// 图书类/// </summary>public class Book {     /// <summary>     /// 图书 ...