POJ 3155Hard Life(最大密度子图)
论文出处:最小割模型在信息学竞赛终的应用
#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(最大密度子图)的更多相关文章
- POJ 3155 Hard Life 最大密度子图 最大权闭合图 网络流 二分
http://poj.org/problem?id=3155 最大密度子图和最大权闭合图性质很相近(大概可以这么说吧),一个是取最多的边一个是取最多有正贡献的点,而且都是有选一种必须选另一种的限制,一 ...
- POJ 3155 Hard Life(最大密度子图+改进算法)
Hard Life Time Limit: 8000MS Memory Limit: 65536K Total Submissions: 9012 Accepted: 2614 Case Ti ...
- POJ 3155 Hard Life(最大密度子图)
裸题.输入一个无向图,输出最大密度子图(输出子图结点数和升序编号). 看了<最小割模型在信息学竞赛中的应用——胡伯涛>的一部分,感觉01分数规划问题又是个大坑.暂时还看不懂. 参考http ...
- poj 3155 最大密度子图
思路: 这个还是看的胡伯涛的论文<最小割在信息学竞赛中的应用>.是将最大密度子图问题转化为了01分数规划和最小割问题. 直接上代码: #include <iostream> # ...
- POJ 3155:Hard Life(最大密度子图)
题目链接 题意 给出n个人,和m对有冲突的人.要裁掉一些人,使得冲突率最高,冲突率为存在的冲突数/人数. 思路 题意可以转化为,求出一些边,使得|E|/|V|最大,这种分数规划叫做最大密度子图. 学习 ...
- POJ3155 Hard Life [最大密度子图]
题意:最大密度子图 #include<iostream> #include<cstdio> #include<cstring> #include<algo ...
- poj3155 最大密度子图
求最大密度子图 记得在最后一次寻找的时候记得将进入的边放大那么一点点,这样有利于当每条边都满流的情况下会选择点 #include <iostream> #include <algor ...
- bzoj 1312 最大密度子图
晕,m=0是要输出1(弄的我还找管理员要数据,但明显题意是叫我们输出0呀) 最大密度子图,把边转换成点,然后二分答案,跑最大权闭合子图判定是否可行. #include <cstdio> # ...
- 2017 计蒜之道 初赛 第三场 D. 腾讯狼人杀 (点边都带权的最大密度子图)
点边都带权的最大密度子图,且会有必须选的点. 求\(\frac{\sum w_e}{k*(2n-k)}\)的最大值,其中k为子图点数 设\[h(g) = \sum w_e - g*(2nk-k^2)\ ...
随机推荐
- .Net Core 最简洁的约定式依赖注入
.Net Core 最简洁的约定式依赖注入 github:https://github.com/280780363/guc/tree/master/src/Guc.Kernel/Dependency ...
- Circumference of circle
public class Solution { public static void main(String[] args) { Scanner ip = new Scanner(System.in) ...
- Azure Devops (VSTS) Extensions 开发小记
我在使用tfx-cli打包Azure Devops插件时,输出了很黄很黄很亮瞎眼的(尤其是在Visual Studio Code采用了Dark Black Theme的情况下)警告warning: P ...
- [Powershell]导出指定的定时计划任务
<# .NOTES =========================================================================== Created wit ...
- pipeline 多个参数如何传入
1.准备一个json文件 { "NAME" : "Lucy", ", ", "ADDRESS" ...
- Qt Quick 常用元素:ComboBox(下拉列表) 与 ProgressBar(进度条)
一.ComboBox ComboBox,即下拉列表框,由一个列表框和一个标签控件(或编辑控件)组成.ComboBox 的下拉列表是使用 Menu 实现的,列表内的每个条目对应一个 Menultem. ...
- Python学习笔记系列
1.小甲鱼 python 学习系列笔记
- 解决SpringDataJpa实体类中属性顺序与数据库中生成字段顺序不一致的问题
一.在application.yml配置中添加数据库根据实体类自动创建数据库表的配置(这里数据库采用MySQL数据库) jpa: database: MYSQL show-sql: true #Hib ...
- 使用numpy处理数组
def fun_ndarray(): a = [[1,2,7], [-6,-2,-3], [-4,-8,-55] ] b = np.array(a) b = np.abs(b)#取数组的绝对值 pri ...
- iOS block疑难解答
1,为什么需要加__block ARC环境下,一旦Block赋值就会触发copy,__block就会copy到堆上,Block也是__NSMallocBlock.ARC环境下也是存在__NSStack ...