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

#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. 【转】HTTPS 如何保证数据传输的安全性?

    大家都知道,在客户端与服务器数据传输的过程中,HTTP协议的传输是不安全的,也就是一般情况下HTTP是明文传输的.但HTTPS协议的数据传输是安全的,也就是说HTTPS数据的传输是经过加密的. 在客户 ...

  2. [LeetCode] 896. Monotonic Array 单调数组

    An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is mono ...

  3. 关于ProxmoxVE

    1) PVE简介 PVE是Proxmox Virtual Environment(Proxmox虚拟化环境,也通常简称为Proxmox VE)的简称,它是基于QEMU/KVM和LXC的开源服务器虚拟化 ...

  4. 编程哲理小故事:Tina的运动会方阵

    自从接到任务后,Tina一直 烦恼着如何让这群繁忙又缺乏才艺的程序员在运动会开幕式上做出一个有趣的方阵表演. 接到了运动会的方阵表演的任务 时间回到1个月前. Tina正在工位上繁忙地进行着下一期准备 ...

  5. 深入理解C语言 - 指针详解

    一.什么是指针 C语言里,变量存放在内存中,而内存其实就是一组有序字节组成的数组,每个字节有唯一的内存地址.CPU 通过内存寻址对存储在内存中的某个指定数据对象的地址进行定位.这里,数据对象是指存储在 ...

  6. HTML+css基础 表格标签table Table标签属性 td标签属性

    表格标签table:   他是由行与列构成,最小单位是单元格. 行标签  <tr></tr> 单元格标签<td></td> Table标签属性: Bor ...

  7. Java程序使用Alpine Linux报错java.lang.NoClassDefFoundError: Could not initialize class org.xerial.snappy.Snappy解决

    报错内容 Caused by: java.lang.UnsatisfiedLinkError: /tmp/snappy-1.1.7-4a4b576a-c34c-481e-b6ac-9b4abacb11 ...

  8. Base64和本地以及在线图片互转

    package com.ruoyi.common.utils; import java.io.ByteArrayOutputStream; import java.io.FileInputStream ...

  9. Linq 将两个查询结果合称为一个

    var handsonitems = from a in db.DltQuestionHandson join c in db.DltBdChapter on new { a.ChapterCode ...

  10. WPF 精修篇 事件触发器

    原文:WPF 精修篇 事件触发器 事件触发器 一般使用的就是动画 <Grid> <TextBlock Text="事件触发器" Opacity="0.2 ...