传送门[洛谷]

自闭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. 从Word文档粘贴内容至Web编辑器的问题

    Chrome+IE默认支持粘贴剪切板中的图片,但是我要发布的文章存在word里面,图片多达数十张,我总不能一张一张复制吧?Chrome高版本提供了可以将单张图片转换在BASE64字符串的功能.但是无法 ...

  2. HTTP请求时候总是设置的两个参数ConnectionTimeOut和SocketTimeOut

    在HTTP请求时候总是设置两个参数,就是连接超时和Socket超时 public static final String SO_TIMEOUT = "http.socket.timeout& ...

  3. spring4.1.8扩展实战之七:控制bean(BeanPostProcessor接口)

    本章是<spring4.1.8扩展实战>的第七篇,我们来尝试在容器初始化的时候对bean实例做设置: 原文地址:https://blog.csdn.net/boling_cavalry/a ...

  4. 神经网络 fann 教程 英文 以及 翻译 参考

    http://fann.sourceforge.net/fann_en.pdf http://blog.csdn.net/fengshuiyue/article/details/41446257

  5. instanceof关键字用于判断一个引用类型变量所指向的对象是否是一个类(或接口、抽象类、父类)的实例。

    http://lavasoft.blog.51cto.com/62575/79864/    深入Java关键字instanceof 2008-06-02 07:50:43 标签:Java 关键字 休 ...

  6. v-if指令

    <!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. HashMap和布隆过滤器命中性能测试

    package datafilter; import com.google.common.base.Stopwatch; import com.google.common.hash.BloomFilt ...

  8. [LOJ3123] CTSC2019重复

    Description 给定一个⻓为 n 的字符串 s , 问有多少个⻓为 m 的字符串 t 满足: 将 t 无限重复后,可以从中截出一个⻓度为 n 且字典序比 s 小的串. m ≤ 2000 n ≤ ...

  9. java_第一年_JDBC(3)

    事务 我们在通过JDBC连接数据库并开始交互时,默认情况下是自动提交的,有时由于为了保持业务流程的完整性.提高性能或是使用分布式事务,需要启动支持事务,此时的方法是调用Connection对象的set ...

  10. Python自学第二天学习之《列表》

    一.  列表:list类型,是有序的,可以被修改的. 格式 : li=["cd",1,"gfds",[1,2,3]] 1.类型转换: #字符串转换成列表 b=“ ...