传送门[洛谷]

自闭QAQ 什么玩意QAQ

不是很理解到底在干啥 问了巨佬以后大概是这个样子的

可以看出是最小割模型

对于每一个人 反悔的话就是代价+1

那么连接(s,i) (i,t)分别表示他最后选择赞同还是反对

根据初始状态来填代价

然后针对基友关系 他们之间连 代价为1的无向边

为什么是无向边呢 是因为 他们无论双方在哪个方向反对 只要不属于同一边的话就是有代价的

Edelweiss的PDF里还有这样的一个小补充

对于求一个函数 的最小值(其中

对于(二者取其一)(不同有代价)这样的模型我们也可以用类似的方法建立最小割来求解

比较有趣。附代码。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define inf 20021225
#define ll long long
#define mxm 360010
#define mxn 310
using namespace std; struct edge{int to,lt,f;}e[mxm];
int in[mxn],s,t,cnt=1,dep[mxn];
void add(int x,int y,int f)
{
e[++cnt].to=y;e[cnt].lt=in[x];e[cnt].f=f;in[x]=cnt;
e[++cnt].to=x;e[cnt].lt=in[y];e[cnt].f=0;in[y]=cnt;
}
queue<int> que;
bool bfs()
{
memset(dep,0,sizeof(dep));
dep[s]=1;while(!que.empty()) que.pop();
que.push(s);
while(!que.empty())
{
int x=que.front();que.pop();
for(int i=in[x];i;i=e[i].lt)
{
int y=e[i].to;if(dep[y]||!e[i].f) continue;
dep[y]=dep[x]+1;que.push(y);
if(y==t) return true;
}
}
return false;
}
int dfs(int x,int flow)
{
if(x==t||!flow) return flow;
int cur=flow;
for(int i=in[x];i;i=e[i].lt)
{
int y=e[i].to;
if(dep[y]==dep[x]+1&&e[i].f)
{
int tmp=dfs(y,min(e[i].f,cur));
cur-=tmp;e[i].f-=tmp;e[i^1].f+=tmp;
if(!cur) return flow;
}
}
dep[x]=-1;return flow-cur;
}
int dinic()
{
int ans=0;
while(bfs())
ans+=dfs(s,inf);
return ans;
}
int main()
{
int n,m,x,y;
while(scanf("%d%d",&n,&m))
{
if(n==0&&m==0) break;
s=n+1;t=s+1;
memset(in,0,sizeof(in));
cnt=1;
for(int i=1;i<=n;i++)
{
scanf("%d",&x);
if(x) add(s,i,1),add(i,t,0);
else add(s,i,0),add(i,t,1);
}
for(int i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
add(x,y,1);add(y,x,1);
}
printf("%d\n",dinic());
}
return 0;
}

SPOJ1693 COCONUTS - Coconuts的更多相关文章

  1. spoj 1693 COCONUTS - Coconuts【最小割】

    s向所有信仰1的人连(s,i,1),所有信仰0的人连(i,t,1),对于朋友关系,连接双向边,流量为1.跑最大流的结果即为答案. 考虑这样做的意义.最小割就是把总点集分割为两个点集S,T,使得所有\( ...

  2. 2016 长春东北赛---Coconuts(离散化+DFS)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5925 Problem Description TanBig, a friend of Mr. Frog ...

  3. hdu 5925 Coconuts 离散化+dfs

    Coconuts Time Limit: 9000/4500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem ...

  4. HDU 5925 Coconuts 【离散化+BFS】 (2016CCPC东北地区大学生程序设计竞赛)

    Coconuts Time Limit: 9000/4500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  5. SPOJ Coconuts 最大流 最小割

    A group of n castle guards are voting to determine whether African swallows can carry coconuts. Whil ...

  6. Coconuts HDU - 5925 (二维离散化求连通块的个数以及大小)

    题目链接: D - Coconuts  HDU - 5925 题目大意:首先是T组测试样例,然后给你n*m的矩阵,原先矩阵里面都是白色的点,然后再输入k个黑色的点.这k个黑色的点可能会使得原先白色的点 ...

  7. Coconuts, Revisited(递推+枚举+模拟)

    Description The short story titled Coconuts, by Ben Ames Williams, appeared in the Saturday Evening ...

  8. HDU 5925 Coconuts 离散化

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5925 Coconuts Time Limit: 9000/4500 MS (Java/Others) ...

  9. Coconuts HDU - 5925 二维离散化 自闭了

    TanBig, a friend of Mr. Frog, likes eating very much, so he always has dreams about eating. One day, ...

随机推荐

  1. 2017ICPC沈阳网络赛 HDU 6205 -- card card card(最大子段和)

    card card card Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  2. GIS网络分析

    https://wenku.baidu.com/view/297ec6a90029bd64783e2cb2.html 缓冲区分析 点线面的数据分析 分布式存储与分析 并行计算 #分布式存储与并行计算# ...

  3. redux简单使用

    在前面的随便中有简单的使用过redux和react-redux,但是感觉写在一起,总是理不清楚,后面看了技术胖老师关于redux的视频后,感觉自己又有了新的理解,在这里简单记录一下. 项目准备 首先安 ...

  4. subprocess.Popen运行报错WindowsError: [Error 740]

    subprocess.Popen在win10下运行报740错时 使用os.popen替换,运行OK,exe程序成功启动 import subprocess import uiautomation as ...

  5. jacoco + ant远程统计(tomcat/spring boot)服务的代码覆盖率

    什么是Jacoco? Jacoco(java code coverage)是一个开源的Java代码覆盖率工具,Jacoco可以嵌入到Ant .Maven中,并提供了EclEmma Eclipse插件, ...

  6. 第九届ECNU Coder K.计软联谊

    题目链接:http://acm.ecnu.edu.cn/contest/16/problem/K/ 题目: K. 计软联谊 Time limit per test: 7.0 seconds Time ...

  7. 535D Tavas and Malekas

    题目大意 给你一个串和m个下标 问你一个长度为n的串每一个下标开始的后缀的前缀都包含给定的串的方案数 分析 对于给定的串求出z数组 对于两个串不重叠的情况就是中间都不包含的数随便填即可 对于重叠的情况 ...

  8. Python中import的使用方法

    源文出处: "import"的本质参照: Python中import机制 python导入自定义模块和包

  9. 16/8/23_CSS自动换行

    转载:http://blog.csdn.net/ye987987/article/details/8011875   自动换行问题,正常字符的换行是比较合理的,而连续的数字和英文字符常常将容器撑大,挺 ...

  10. php远程抓取(下载)文件到本项目指定目录中

    function httpcopy($url, $file="", $timeout=60) { $file = empty($file) ? pathinfo($url,PATH ...