【bzoj2768/bzoj1934】[JLOI2010]冠军调查/[Shoi2007]Vote 善意的投票 最小割
bzoj2768
题目描述
输入
输出
样例输入
3 3
1 0 0
1 2
1 3
2 3
样例输出
1
bzoj1934
同上。。。
题解
最小割
s代表观点为0,t代表观点为1,每个点和他的相反观点连边,朋友之间互相连边,跑dinic即可。
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
queue<int> q;
int head[310] , to[200000] , val[200000] , next[200000] , cnt = 1 , dis[310] , s , t;
void add(int x , int y , int z)
{
to[++cnt] = y , val[cnt] = z , next[cnt] = head[x] , head[x] = cnt;
to[++cnt] = x , val[cnt] = 0 , next[cnt] = head[y] , head[y] = cnt;
}
bool bfs()
{
int i , x;
while(!q.empty()) q.pop();
memset(dis , 0 , sizeof(dis));
dis[s] = 1;
q.push(s);
while(!q.empty())
{
x = q.front() , q.pop();
for(i = head[x] ; i ; i = next[i])
{
if(val[i] && !dis[to[i]])
{
dis[to[i]] = dis[x] + 1;
if(to[i] == t) return 1;
q.push(to[i]);
}
}
}
return 0;
}
int dinic(int x , int low)
{
if(x == t) return low;
int temp = low , i , k;
for(i = head[x] ; i ; i = next[i])
{
if(val[i] && dis[to[i]] == dis[x] + 1)
{
k = dinic(to[i] , min(temp , val[i]));
if(!k) dis[to[i]] = 0;
val[i] -= k , val[i ^ 1] += k;
if(!(temp -= k)) break;
}
}
return low - temp;
}
int main()
{
int n , m , i , x , y , ans = 0;
scanf("%d%d" , &n , &m);
s = 0 , t = n + 1;
for(i = 1 ; i <= n ; i ++ )
{
scanf("%d" , &x);
if(x) add(s , i , 1);
else add(i , t , 1);
}
while(m -- ) scanf("%d%d" , &x , &y) , add(x , y , 1) , add(y , x , 1);
while(bfs()) ans += dinic(s , 0x7fffffff);
printf("%d\n" , ans);
return 0;
}
【bzoj2768/bzoj1934】[JLOI2010]冠军调查/[Shoi2007]Vote 善意的投票 最小割的更多相关文章
- 【BZOJ2768】[JLOI2010]冠军调查/【BZOJ1934】[Shoi2007]Vote 善意的投票 最小割
[BZOJ2768][JLOI2010]冠军调查 Description 一年一度的欧洲足球冠军联赛已经进入了淘汰赛阶段.随着卫冕冠军巴萨罗那的淘汰,英超劲旅切尔西成为了头号热门.新浪体育最近在吉林教 ...
- BZOJ 1934: [Shoi2007]Vote 善意的投票 最小割
1934: [Shoi2007]Vote 善意的投票 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnl ...
- 最小投票BZOJ 1934([Shoi2007]Vote 善意的投票-最小割)
上班之余抽点时间出来写写博文,希望对新接触的朋友有帮助.今天在这里和大家一起学习一下最小投票 1934: [Shoi2007]Vote 好心的投票 Time Limit: 1 Sec Memory L ...
- B1934 [Shoi2007]Vote 善意的投票 最小割
一开始不太会,结果看完题解就是一个建图的网络流.然后就结了. 题干: 题目描述 幼儿园里有n个小朋友打算通过投票来决定睡不睡午觉.对他们来说,这个问题并不是很重要,于是他们决定发扬谦让精神.虽然每个人 ...
- bzoj1934 Vote 善意的投票 最小割(最大匹配)
题目传送门 题目大意:很多小朋友,每个小朋友都有自己的立场,赞成或者反对,如果投了和自己立场不同的票会得到一个能量.又有很多朋友关系,如果一个人和他的一个朋友投的票不同,也会得到一个能量,现在问,通过 ...
- bzoj1934: [Shoi2007]Vote 善意的投票
最大流..建图方式都是玄学啊.. //Dinic是O(n2m)的. #include<cstdio> #include<cstring> #include<cctype& ...
- bzoj1934: [Shoi2007]Vote 善意的投票(显然最小割)
1934: [Shoi2007]Vote 善意的投票 题目:传送门 题解: 明显的不能再明显的最小割... st连同意的,不同意的连ed 朋友之间两两连边(即双向边) 流量都为1... 为啥: 一个人 ...
- 1934: [Shoi2007]Vote 善意的投票
1934: [Shoi2007]Vote 善意的投票 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 1174 Solved: 723[Submit][S ...
- BZOJ_1934_[Shoi2007]Vote 善意的投票
BZOJ_1934_[Shoi2007]Vote 善意的投票 Description 幼儿园里有n个小朋友打算通过投票来决定睡不睡午觉.对他们来说,这个问题并不是很重要,于是他们决定发扬谦让精神.虽然 ...
随机推荐
- jQuery获取data-*属性值
下面就详细介绍四种方法获取data-*属性的值 <li id="getId" data-id="122" data-vice-id="11&qu ...
- 介绍三种PHP加密解密算法
PHP加密解密算法 这里主要介绍三种常用的加密解密算法:方法一: /** * @param $string 要加密/解密的字符串 * @param string $operation 类型,ENCOD ...
- 自定义控件,继承自 ListView
public class MyListView extends ListView { /** * 如果在xml中创建并设置了style,就会调用三个参数的. * * @param context * ...
- 九、IIC驱动原理分析
学习目标:学习IIC驱动原理: 一.IIC总线协议 IIC串行总线包括一条数据线(SDA)和一条时钟线(SCL),支持“一主多从”和“多主机”模式:每个从机设备都有唯一的地址来识别. 图 1 IIC ...
- Redis缓存数据库的安装与配置(2)
1.为php安装redis客户端扩展 wget https://github.com/nicolasff/phpredis/archive/master.zip tar xf phpredis-mas ...
- C语言实现斐波那契数列
1.函数一用递归实现 2.函数二用循环实现 #include<stdio.h> #include<stdlib.h> #pragma warning(disable:4996) ...
- Vee-validate学习
Vee-validate使用方法 首先引入 <script src="https://cdn.bootcss.com/vee-validate/2.0.9/vee-validate.j ...
- linux 操作之一 如何在linux将本地数据*.sql文件导入到linux 云服务器上的mysql数据库
liunx 版本ubuntu 16.4 mysql 版本 5.6 1)准备*.sql文件 (* 是准备导入的sql文件的名字) 2)liunx 远程客户端 SecureCRT 7.0 alt+p ...
- ethtool speed HowTo : Change Speed and Duplex of Ethernet card in Linux
To change Speed and Duplex of an ethernet card, we can use ethtool - a Linux utility for Displaying ...
- Percona-Tookit工具包之pt-mysql-summary
Preface Sometimes we need to collect information of MySQL server as a report when we first ...