论文出处:最小割模型在信息学竞赛终的应用

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std; const double eps = 1e-;
const int inf = 0x3f3f3f3f;
const int maxn = + ;
const int maxe = + ;
struct edge{
int to, next;
double w;
} ed[maxe*];
int head[maxn], tot;
int n, m, ans;
int sp, tp, degree[maxn], d[maxn];
struct E{
int u, v;
}p[maxe];
bool vis[maxn];
inline void init(){
memset( head, -, sizeof(head) );
tot = ;
} inline void add( int u, int v, double w ){
ed[++tot].to = v; ed[tot].w = w; ed[tot].next = head[u]; head[u] = tot;
ed[++tot].to = u; ed[tot].w = ; ed[tot].next = head[v]; head[v] = tot;
} inline bool bfs(){
memset( d, , sizeof(d) );
queue<int> q;
d[sp] = ;
q.push(sp);
while( q.size() ){
int x = q.front();
q.pop();
for( int i=head[x]; ~i; i=ed[i].next ){
int y = ed[i].to;
if( ed[i].w>=eps && !d[y] ){
d[y] = d[x] + ;
q.push(y);
if( y==tp ) return ;
}
}
}
return ;
} inline double dfs( int x, double flow ){
if( x==tp ) return flow;
double res = flow, k;
for( int i=head[x]; ~i&&res>=eps; i=ed[i].next ){
int y = ed[i].to;
if( ed[i].w>=eps && d[y]==d[x]+ ){
k = dfs( y, min(res, ed[i].w) );
if( k<eps ) d[y] = ;
ed[i].w -= k;
ed[i^].w += k;
res -= k;
}
}
return flow-res;
} inline double check( double g ){
init();
for( int i=; i<m; i++ ){
add( p[i].u, p[i].v, );
add( p[i].v, p[i].u, );
}
double U = m;
for( int i=; i<=n; i++ ){
add( sp, i, U );
add( i, tp, U+*g-degree[i] );
}
double maxflow=, flow;
while( bfs() ){
while( (flow=dfs(sp, inf))>=eps ) maxflow += flow;
}
return (U*n-maxflow)*0.5;
} inline void find_cut( int x ){
for( int i=head[x]; ~i; i=ed[i].next ){
int y = ed[i].to;
if( ed[i].w>=eps && !vis[y] ){
vis[y] = ;
ans ++;
find_cut(y);
}
}
} int main(){
// freopen("in.txt", "r", stdin);
while(~scanf("%d%d", &n, &m)){
if( !m ){
puts("1\n1");
continue;
}
memset( degree, , sizeof(degree) );
memset( vis, , sizeof(vis) );
sp = ; tp = n+;
for( int i=; i<m; i++ ){
scanf("%d%d", &p[i].u, &p[i].v);
degree[p[i].u] ++;
degree[p[i].v] ++;
}
double l = , r = m;
double tmp = 1.0/n/n; //这里需要设定一个上界啊,不然WA,具体证明请看论文
while( r-l>=tmp ){
double mid = (l+r)*0.5;
if( check(mid)<eps ) r = mid;
else l = mid;
}
check(l); //保证精度
vis[sp] = ;
find_cut(sp);
printf("%d\n", ans);
for( int i=; i<=n; i++ ) if(vis[i]) printf("%d\n", i);
} return ;
}

POJ 3155Hard Life(最大密度子图)的更多相关文章

  1. POJ 3155 Hard Life 最大密度子图 最大权闭合图 网络流 二分

    http://poj.org/problem?id=3155 最大密度子图和最大权闭合图性质很相近(大概可以这么说吧),一个是取最多的边一个是取最多有正贡献的点,而且都是有选一种必须选另一种的限制,一 ...

  2. POJ 3155 Hard Life(最大密度子图+改进算法)

    Hard Life Time Limit: 8000MS   Memory Limit: 65536K Total Submissions: 9012   Accepted: 2614 Case Ti ...

  3. POJ 3155 Hard Life(最大密度子图)

    裸题.输入一个无向图,输出最大密度子图(输出子图结点数和升序编号). 看了<最小割模型在信息学竞赛中的应用——胡伯涛>的一部分,感觉01分数规划问题又是个大坑.暂时还看不懂. 参考http ...

  4. poj 3155 最大密度子图

    思路: 这个还是看的胡伯涛的论文<最小割在信息学竞赛中的应用>.是将最大密度子图问题转化为了01分数规划和最小割问题. 直接上代码: #include <iostream> # ...

  5. POJ 3155:Hard Life(最大密度子图)

    题目链接 题意 给出n个人,和m对有冲突的人.要裁掉一些人,使得冲突率最高,冲突率为存在的冲突数/人数. 思路 题意可以转化为,求出一些边,使得|E|/|V|最大,这种分数规划叫做最大密度子图. 学习 ...

  6. POJ3155 Hard Life [最大密度子图]

      题意:最大密度子图 #include<iostream> #include<cstdio> #include<cstring> #include<algo ...

  7. poj3155 最大密度子图

    求最大密度子图 记得在最后一次寻找的时候记得将进入的边放大那么一点点,这样有利于当每条边都满流的情况下会选择点 #include <iostream> #include <algor ...

  8. bzoj 1312 最大密度子图

    晕,m=0是要输出1(弄的我还找管理员要数据,但明显题意是叫我们输出0呀) 最大密度子图,把边转换成点,然后二分答案,跑最大权闭合子图判定是否可行. #include <cstdio> # ...

  9. 2017 计蒜之道 初赛 第三场 D. 腾讯狼人杀 (点边都带权的最大密度子图)

    点边都带权的最大密度子图,且会有必须选的点. 求\(\frac{\sum w_e}{k*(2n-k)}\)的最大值,其中k为子图点数 设\[h(g) = \sum w_e - g*(2nk-k^2)\ ...

随机推荐

  1. 部署ComsenzDiscuz BBS论坛系统

    1.准备环节 [root@localhost ~]# unzip ComsenzDiscuz-DiscuzX-master.zip //解包 [root@localhost ~]# cd Discuz ...

  2. DP问题(1) : hdu 2577

    题目转自hdu 2577,题目传送门 题目大意: 现给你n个区分大小写的字符串,大小写可用Caps Lock和shift切换(学过计算机的都知道) 但是有一点需要注意(shift是切换,若现在是大写锁 ...

  3. Jena Fuseki安装完成后不能添加数据库

    问题描述:安装Jena成功后可以进入管理页面,无法通过界面选择和查询数据 解决方案: 进入 apache-jena-fuseki-3.12.0\run 修改 shiro.ini 配置文件 注释 /$/ ...

  4. JVM系列之五:垃圾回收

    . jdk1.7的堆内存 1. 堆(Java堆) 堆是java虚拟机所管理的内存中最大的一块内存区域,也是被各个线程共享的内存区域, 在JVM启动时创建,该内存区域存放了对象实例(包括基本类型的变量及 ...

  5. Scala函数式编程实现排序算法

    记得<Function Thinking>这本书中提到,现在的编程范式有两类,一类是“命令式编程”,另一类是“函数式编程”,现在我们最常使用的许多语言像c.c++.java都是命令式的,但 ...

  6. http与tcp,udp的区别

    1.网络协议的概念 (1)在学习网络课程的时候,老师会讲iso七层模型,有应用层 表示层 会话层 传输层 网络层 数据链路层 物理层,其中http就属于应用层,tcp与udp是属于传输层,如图1.1( ...

  7. Navicat Premium 12 安装与激活

    一.Navicat Premium 12下载 官方下载地址:https://www.navicat.com.cn/download/navicat-premium 百度云盘:https://pan.b ...

  8. python]用eval强制将字符串转换为字典变量时候出错:NameError: name 'null' is not defined[python]用eval函数 字符串转dict

    本博客已搬家至个人网站 在路上 - On the way 下面的 技术 分类. 你可以通过点击 更新帖子 [已解决]Python中,用eval强制将字符串转换为字典变量时候出错:NameError: ...

  9. 元类理解与元类编程 《Python3网络爬虫开发》中第九章代理的使用代码Crawler中代码的理解

    __new__与__init__的理解 __new__()方法是在创建实例之前被调用的,它的作用是创建一个实例,然后返回该实例对象,它是一个静态方法. __init__() 当实例被创建完成之后被调用 ...

  10. springBoot获取@NotBlank,@NotNull注解的message信息

    概述 springBoot后台验证接收的参数是否不合法时,会抛出一个BlndException异常,获取message的自定义信息并返回 验证 UserEntity类 @Data @Entity @T ...