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)\ ...
随机推荐
- cf1207解题报告
cf1207解题报告 A 模拟 #include <bits/stdc++.h> #define ll long long using namespace std; ll T,a,b,c, ...
- [LeetCode] 554. Brick Wall 砖头墙壁
There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The b ...
- [LeetCode] 22. Generate Parentheses 生成括号
Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...
- K8s 集群安装(一)
01,集群环境 三个节点 master node1 node2 IP 192.168.0.81 192.168.0.82 192.168.0.83 环境 centos 7 centos 7 cen ...
- HDU 3686 Traffic Real Time Query System(点双连通)
题意 给定一张 \(n\) 个点 \(m\) 条边的无向图,\(q\) 次询问,每次询问两边之间的必经之点个数. 思路 求两点之间必经之边的个数用的是边双缩点,再求树上距离.而对比边双和点双之 ...
- .NET Core3.0 Autofac注入
参考地址:https://docs.autofac.org/en/latest/examples/index.html 1. nuget :Autofac.Extensions.DependencyI ...
- 用Java编程能给物联网(IoT)带来什么优势与不同?
用Java编程能给物联网(IoT)带来什么优势与不同? 这是一个不太容易回答的问题,也是一个适合拿出来与大家讨论的一个话题~首先需要聊聊物联网硬件与嵌入式设备有什么不同.嵌入式设备通常是一个软件一体的 ...
- js 编译原理
引擎:从头到尾负责整个javaScript 程序的编译过程和执行过程. 编译器: 负责语法分析以及代码的生成. 作用域:负责收集并维护由所有声明的标识符(变量)组成的一系列查询, 并实施一套非常严格的 ...
- 转载:string、const char*、 char* 、char[]相互转换
本文转自:https://blog.csdn.net/rongrongyaofeiqi/article/details/52442169 一:转化总结形式如下: 使用时,要对源格式和目标格式进行初始化 ...
- Isilon Gen6的换盘步骤
When a drive is faulted and ready for replacement, OneFS will illuminate the Front Panel Fault LED a ...