网络流(最大密集度子图,分数规划):UvaLive 3709 Hard Life

时间:2022-04-24 23:35:54

  John is a Chief Executive Officer at a privately owned medium size company. The owner of the company has decided to make his son Scott a manager in the company. John fears that the owner will ultimately give CEO position to Scott if he does well on his new manager position, so he decided to make Scott's life as hard as possible by carefully selecting the team he is going to manage in the company.

  John knows which pairs of his people work poorly in the same team. John introduced a hardness factor of a team -- it is a number of pairs of people from this team who work poorly in the same team divided by the total number of people in the team. The larger is the hardness factor, the harder is this team to manage. John wants to find a group of people in the company that are harderst to manage and make it Scott's team. Please, help him.

网络流(最大密集度子图,分数规划):UvaLive 3709 Hard Life

  In the example on the picture the hardest team consists of people 1, 2, 4, and 5. Among 4 of them 5 pairs work poorly in the same team, thus hardness factor is equal to 网络流(最大密集度子图,分数规划):UvaLive 3709 Hard Life . If we add person number 3 to the team then hardness factor decreases to 网络流(最大密集度子图,分数规划):UvaLive 3709 Hard Life .

Input

The input will contain several test cases, each of them as described below. Consecutive test cases are separated by a single blank line.

  The first line of the input contains two integer numbers n
and m

(1网络流(最大密集度子图,分数规划):UvaLive 3709 Hard Lifen网络流(最大密集度子图,分数规划):UvaLive 3709 Hard Life100, 0网络流(最大密集度子图,分数规划):UvaLive 3709 Hard Lifem网络流(最大密集度子图,分数规划):UvaLive 3709 Hard Life1000)
. Here n
is a total number of people
in the company (people are numbered from 1 to n
), and m
is the number
of pairs of people who work poorly in the same team. Next m
lines
describe those pairs with two integer numbers ai
and bi

(1网络流(最大密集度子图,分数规划):UvaLive 3709 Hard Lifeai, bi网络流(最大密集度子图,分数规划):UvaLive 3709 Hard Lifen, ai网络流(最大密集度子图,分数规划):UvaLive 3709 Hard Lifebi)
on a line. The order of people in a pair is arbitrary and no
pair is listed twice.

Output

For each test case, the output must follow the description below.
The outputs of two consecutive cases will be separated by a blank line.

  Write to the output an integer number k

(1网络流(最大密集度子图,分数规划):UvaLive 3709 Hard Lifek网络流(最大密集度子图,分数规划):UvaLive 3709 Hard Lifen)
-- the
number of people in the hardest team, followed by k
lines listing people
from this team in ascending order. If there are multiple teams with the
same hardness factor then write any one.

Note, that in the last example any team has hardness factor of zero,
and any non-empty list of people is a valid answer.

Sample Input

5 6
1 5
5 4
4 2
2 5
1 2
3 1 4 0

Sample Output

4
1
2
4
5 1
1

  

  胡博涛论文有提到。

  WA67发,都不敢刷Uva了。

  原因是最后的答案不能用lam获得,因为lam不一定是最优解,而且还会得到错误答案。

 #include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
using namespace std;
const int maxn = ;
const int maxm = ;
const double INF = 0x3fffffff;
const double eps = 1e-;
int n,m; struct Max_Flow{
int cnt,fir[maxn],fron[maxn];
int tot,to[maxm],nxt[maxm];
double cap[maxm];queue<int>q;
int dis[maxn],gap[maxn],path[maxn];
void Init(int tot_=){
memset(fir,,sizeof(fir));
memset(dis,,sizeof(dis));
memset(gap,,sizeof(gap));
cnt=;tot=tot_;
}
void add(int a,int b,double c){
nxt[++cnt]=fir[a];
fir[a]=cnt;
cap[cnt]=c;
to[cnt]=b;
} void addedge(int a,int b,double c){
add(a,b,c);
add(b,a,);
} bool BFS(int s,int t){
dis[t]=;q.push(t);
while(!q.empty()){
int x=q.front();q.pop();
for(int i=fir[x];i;i=nxt[i])
if(!dis[to[i]]){
dis[to[i]]=dis[x]+;
q.push(to[i]);
}
}
return dis[s];
} double Aug(int s,int t){
int p=t;double f=INF;
while(p!=s){
f=min(f,cap[path[p]]);
p=to[path[p]^];
}
p=t;
while(p!=s) {
cap[path[p]]-=f;
cap[path[p]^]+=f;
p=to[path[p]^];
}
return f;
} double ISAP(int s,int t){
if(!BFS(s,t));
for(int i=s;i<=t;i++)gap[dis[i]]+=;
for(int i=s;i<=t;i++)fron[i]=fir[i];
int p=s;double ret=;
while(dis[s]<=tot){
if(p==t){
ret+=Aug(s,t);
p=s;
}
int &ii=fron[p];
for(;ii;ii=nxt[ii])if(cap[ii])
if(dis[p]==dis[to[ii]]+)
break;
if(ii)
path[p=to[ii]]=ii;
else{
if(--gap[dis[p]]==)break;
int minn=tot+;
for(int i=fir[p];i;i=nxt[i])
if(cap[i]>eps)minn=min(minn,dis[to[i]]);
gap[dis[p]=minn+]+=;fron[p]=fir[p];
if(p!=s)p=to[path[p]^];
}
}
return ret;
}
}isap; int vis[maxn],ans;
void DFS(int x){
vis[x]=true;
if(x>=&&x<=n)ans+=;
for(int i=isap.fir[x];i;i=isap.nxt[i])
if(!vis[isap.to[i]]&&isap.cap[i]>eps)
DFS(isap.to[i]);
} int x1[maxm],y1[maxm];
void Build(double lam){
isap.Init(n+m+);
for(int i=;i<=m;i++){
int u=x1[i],v=y1[i];
isap.addedge(,n+i,1.0);
isap.addedge(n+i,u,INF);
isap.addedge(n+i,v,INF);
}
for(int i=;i<=n;i++)
isap.addedge(i,n+m+,lam);
} void Solve(){ int s=,t=n+m+;
double l=,r=m,lam;
while (r-l>=1.0/n/n){
lam=(l+r)/;Build(lam);
double ret=isap.ISAP(s,t);
if(1.0*m-ret<eps)r=lam;
else l=lam;
}
Build(l);isap.ISAP(s,t);
memset(vis,,sizeof(vis));
ans=;DFS(s);printf("%d\n",ans);
for (int i=;i<=n;i++)
if(vis[i])printf("%d\n", i);
} int main(){
while(scanf("%d%d",&n,&m)!=EOF){
for(int i=;i<=m;i++)
scanf("%d%d",&x1[i],&y1[i]);
if(!m){
printf("1\n1\n");
continue;
}
Solve();
}
return ;
}

网络流(最大密集度子图,分数规划):UvaLive 3709 Hard Life的更多相关文章

  1. 【BZOJ2285】&lbrack;SDOI2011&rsqb;保密(分数规划,网络流)

    [BZOJ2285][SDOI2011]保密(分数规划,网络流) 题面 BZOJ 洛谷 题解 首先先读懂题目到底在干什么. 发现要求的是一个比值的最小值,二分这个最小值\(k\),把边权转换成\(t- ...

  2. 【BZOJ3232】圈地游戏(分数规划,网络流)

    [BZOJ3232]圈地游戏(分数规划,网络流) 题面 BZOJ 题解 很神仙的一道题. 首先看到最大化的比值很容易想到分数规划.现在考虑分数规划之后怎么计算贡献. 首先每条边的贡献就变成了\(mid ...

  3. 【XSY2718】gift 分数规划 网络流

    题目描述 有\(n\)个物品,买第\(i\)个物品要花费\(a_i\)元.还有\(m\)对关系:同时买\(p_i,q_i\)两个物品会获得\(b_i\)点收益. 设收益为\(B\),花费为\(A\), ...

  4. 【BZOJ4819】新生舞会(分数规划,网络流)

    [BZOJ4819]新生舞会(分数规划,网络流) 题面 BZOJ Description 学校组织了一次新生舞会,Cathy作为经验丰富的老学姐,负责为同学们安排舞伴.有n个男生和n个女生参加舞会 买 ...

  5. 【BZOJ3597】方伯伯运椰子(分数规划,网络流)

    [BZOJ3597]方伯伯运椰子(分数规划,网络流) 题解 给定了一个满流的费用流模型 如果要修改一条边,那么就必须满足流量平衡 也就是会修改一条某两点之间的路径上的所有边 同时还有另外一条路径会进行 ...

  6. &lbrack;SCOI2018&rsqb;游泳池(计算几何+分数规划+最大权闭合子图)

    题目链接 https://www.luogu.org/problemnew/show/U56187 注:题面参考了网上的其他博客,并非原题题面,因此数据范围可能有误.数据为原创数据. 题解 其实就是许 ...

  7. bzoj 3232 圈地游戏——0&sol;1分数规划&lpar;或网络流&rpar;

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3232 当然是0/1分数规划.但加的东西和减的东西不在一起,怎么办? 考虑把它们合在一起.因为 ...

  8. BZOJ2285 &lbrack;SDOI2011&rsqb;保密 【01分数规划 &plus; 网络流】

    题目 现在,保密成为一个很重要也很困难的问题.如果没有做好,后果是严重的.比如,有个人没有自己去修电脑,又没有拆硬盘,后来的事大家都知道了. 当然,对保密最需求的当然是军方,其次才是像那个人.为了应付 ...

  9. bzoj 3232 圈地游戏 —— 01分数规划&plus;最小割建图&lpar;最大权闭合子图&rpar;

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3232 心烦意乱的时候调这道题真是...越调越气,就这样过了一晚上... 今天再认真看看,找出 ...

随机推荐

  1. SWT组件添加事件的四种方式

    在我们CS日常开发过程中会经常去为组件添加事件,我们常用的为AWT与SWT.SWT的事件模型是和标准的AWT基本一样的.下面将按照事件的四种写法来实现它. 一.匿名内部类的写法 new MouseAd ...

  2. 3D Touch &quest; 木有6s&comma;也阔以玩!!!

    3D Touch 之 Peek & Pop 3D Touch 是iOS9之后专为 iPhone6s 机型加入的新特性,这一新技术移植于 Mac Book 上的 ForceTouch 更准确地说 ...

  3. Android*行之走进zxing&comma;轻松实现二维码扫描

    现在很多App都集成了扫一扫功能,最常用的微信.QQ.手机助手等.二维码也使得生活变得更加简洁,扫一扫订餐.扫一扫下载等等.那么,说到二维码,我们不得不提Google一个开源的扫码框架:zxing. ...

  4. lua math libary

    函数名 描述 示例 结果 pi 圆周率 math.pi 3.1415926535898 abs 取绝对值 math.abs(-2012) 2012 ceil 向上取整 math.ceil(9.1) 1 ...

  5. Vue-发布订阅机制(bus&rpar;实现非父子组件的传值

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. Zookeeper三个监听案例

    一.监听某一节点内容 /** * @author: PrincessHug * @date: 2019/2/25, 14:28 * @Blog: https://www.cnblogs.com/Hel ...

  7. 【洛谷4770】 &lbrack;NOI2018&rsqb;你的名字(SAM,线段树合并)

    传送门 洛谷 Solution 做过的比较玄学的后缀自动机. 果然就像\(Tham\)所讲,后缀自动机这种东西考场考了不可能做的出来的... 考虑如果\(l=1,r=|S|\)的怎么做? 直接建后缀自 ...

  8. GraphQL循环引用的问题

    下面的代码中, 由于friends字段引用了PersonType字段,而friends本身又是PersonType的一部分,在运行的时候会报错: Expected undefined to be a ...

  9. sublime很常用快捷方式演示

                    来自为知笔记(Wiz)

  10. mysql 中 group&lowbar;concat&lpar;&rpar;用法

     基本语法:group_concat([DISTINCT] 要连接的字段 [Order BY  排序字段 ASC/DESC] [Separator '分隔符']) 初始数据:              ...