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)\ ...
随机推荐
- [NOIP2015]联合权值
1.题面 2.总结 第一次回忆一下当年的题目.但是这道题已经做烂了,只是看还记得树遍历会写么. 然后我写了一下,有点费劲,交上去之后只有70,比较尴尬,看了下去年5月写的代码,发现完全不是一个感觉啊. ...
- Sentinel: 分布式系统的流量防卫兵
前言 在 Spring Cloud 体系中,熔断降级我们会使用 Hystrix 框架,限流通常会在 Zuul 中进行处理,Zuul 中没有自带限流的功能,我们可以自己做限流或者集成第三方开源的限流框架 ...
- HDU 4005 The war(边双连通)
题意 给定一张 \(n\) 个点 \(m\) 条边的无向连通图,加入一条边,使得图中权值最小的桥权值最大,如果能使图中没有桥则输出 \(-1\). 思路 先对原图边双缩点,然后变成了一棵树.在 ...
- asp.net mvc移除X-AspNet-Version、X-AspNetMvc-Version、Server
asp.net mvc程序部署到IIS,,返回的HTTP头中包含Server, X-Powered-By, 和 X-AspNet-Version.X-AspNet-Version信息. 这些信息有时给 ...
- c++ 使用 vcpkg
1. 打开下载地址:https://github.com/Microsoft/vcpkg 2. 直接下载到本地某个盘 3. 配置环境变量: 4. 打开下载到本地的vcpkg有可能叫vcpkg-mast ...
- windows 7输入regedit 打不开注册表
Win 10 win 7 Win7 regedit 打不开 怎么打不开 打不开了怎么办 没反应 不能打开 注册表? 1.使用键盘快捷键 win+r,打开运行工具. 2.在输入框内输入gepedit.m ...
- myeclipse配置springmvc教程
之前一直是使用Eclipse创建Web项目,用IDEA和MyEclipse的创建SpringMVC项目的时候时不时会遇到一些问题,这里把这个过程记录一下,希望能帮助到那些有需要的朋友.我是用的是MyE ...
- nginx location笔记
nginx location笔记= 开头表示精确匹配^~ 开头表示uri以某个常规字符串开头,理解为匹配 url路径即可.nginx不对url做编码,因此请求为/static/20%/aa,可以被规则 ...
- Java中调用存储过程
dao层: import java.util.Map; public interface AppGthdDao { public String gthd(Map map); } mapper层 < ...
- WebStrom安装Markdown插件
安装步骤 File→Settings→Plugins→关键字搜索markdown→选择Markdown Navigator→点击Install→出现下载弹窗,等待下载完毕→重启Webstrom 效果预 ...