Time Limit: 8000MS   Memory Limit: 65536K
Total Submissions: 8482   Accepted: 2461
Case Time Limit: 2000MS   Special Judge

Description

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 hardest to manage and make it Scott’s team. Please, help him.

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 54. If we add person number 3 to the team then hardness factor decreases to 65.

Input

The first line of the input file contains two integer numbers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 1000). 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 ≤ aibi ≤ nai ≠ bi) on a line. The order of people in a pair is arbitrary and no pair is listed twice.

Output

Write to the output file an integer number k (1 ≤ k ≤ n) — 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.

Sample Input

sample input #1
5 6
1 5
5 4
4 2
2 5
1 2
3 1 sample input #2
4 0

Sample Output

sample output #1
4
1
2
4
5 sample output #2
1
1

Hint

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

Source

关于这道题《最小割模型在信息学竞赛中的应用》,这篇论文里有讲到,而且解释给的很详细,可以去翻论文。
 #include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <cmath>
const double eqs = 1e- ;
const int N = + , M = + ;
using namespace std ;
int n , m , head[N] , cnt , s , t , du[N] , num , cur[N] , node[N] ;
struct ide
{
int u , v ;
} edge[M] ;
struct id
{
int fro ,nxt , to ; double w ;
} links[] ; void add( int u , int v , double val )
{
links[++cnt].fro = u , links[cnt].to = v ;
links[cnt].nxt = head[u] , links[cnt].w = val , head[u] = cnt ;
} void Init( )
{
scanf( "%d%d" , &n , &m ) ; s = , t = n + ;
for( int x = ; x <= m ; ++x )
{
scanf( "%d%d" , &edge[x].u , &edge[x].v ) ;
++du[edge[x].u] , ++du[edge[x].v] ;
}
} int dis[N] ; queue< int > Q ;
bool bfs( )
{
memset( dis , - , sizeof(dis) ) ;
dis[s] = ; Q.push( s ) ;
while( !Q.empty( ) )
{
int u = Q.front( ) ; Q.pop( ) ;
for( int i = head[u] ; ~i ; i = links[i].nxt )
{
int v = links[i].to ;
if( dis[v] < && fabs( links[i].w ) > eqs )
{
dis[v] = dis[u] + ;
Q.push( v ) ;
}
}
}
return dis[t] != - ;
} double dfs( int u , double f )
{
if( u == t ) return f ;
double an , cost = 0.00 ;
for( int i = cur[u] ; ~i ; i = links[i].nxt )
{
int v = links[i].to ;
if( dis[v] != dis[u] + ) continue ;
an = dfs( v , min( f - cost , links[i].w ) ) ;
cost += an ; links[i^].w += an , links[i].w -= an ;
if( fabs( links[i].w ) > eqs ) cur[u] = i ;
if( fabs( cost - f ) < eqs ) return cost ;
}
if( fabs( cost ) < eqs ) dis[u] = - ;
return cost ;
} double Dinic( )
{
double ans = 0.00 ;
while( bfs( ) )
{
for( int x = s ; x <= t ; ++x ) cur[x] = head[x] ;
ans += dfs( s , ) ;
}
//cout<<ans<<endl;
return ans ;
} double check( double mid )
{
//cout<<mid<<endl;
cnt = - ; memset( head , - , sizeof(head) ) ;
for( int i = ; i <= n ; ++i )
{ add( s , i , m*1.0 ) , add( i , s , ) ;
add( i , t , m + * mid - du[i] ) ;
add( t , i , ) ;
}
for( int i = ; i <= m ; ++i )
{
add( edge[i].u , edge[i].v , 1.0 ) ;
add( edge[i].v , edge[i].u , 0.0 ) ;
add( edge[i].v , edge[i].u , 1.0 ) ;
add( edge[i].u , edge[i].v , 0.0 ) ;
}
return Dinic( ) ;
} bool vis[N] ;
void flow( int u )
{
vis[u] = true ;
if( u >= && u <= n ) node[++num] = u ;
for( int i = head[u] ; ~i ; i = links[i].nxt )
if( links[i].w > && !vis[links[i].to] ) flow( links[i].to ) ;
} void Solve( )
{
double l = , r = m , minn = 1.00 / n / n ;//cout<<l<<" "<<r<<endl;
while( r - l >= minn )
{
double mid = ( r + l ) / ;
double hg = check( mid ) ; //cout<<l<<" "<<hg<<endl ;
if( ( m * n - hg )* 0.5 > eqs ) l = mid ;
else r = mid ; } check( l ) ; num = ;
flow( s ) ; if( num == ) node[++num] = ;
sort( node + , node + + num ) ;
printf( "%d\n" , num ) ;
for( int x = ; x <= num ; ++x ) printf( "%d\n" , node[x] ) ;
} int main( )
{
// freopen( "poj3155.in" , "r" , stdin ) ;
// freopen( "poj3155.out" , "w" , stdout ) ;
Init( ) ;
Solve( ) ;
// fclose( stdin ) ;
// fclose( stdout ) ;
return ;
}
 

POJ3155 Hard Life的更多相关文章

  1. Bzoj1312 / POJ3155 Neerc2006 Hard Life

    Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 459  Solved: 114 Description 在一家公司中,人事部经理与业务部经理不和.一次 ...

  2. 最大密集子图(01分数规划+二分+最小割)POJ3155

    题意:给出一副连通图,求出一个子图令g=sigma(E)/sigma(V); h[g]=sigma(E)-g*sigma(V):设G是最优值 则当h[g]>0:g<G h[g]<0, ...

  3. POJ3155 Hard Life [最大密度子图]

      题意:最大密度子图 #include<iostream> #include<cstdio> #include<cstring> #include<algo ...

  4. poj3155 最大密度子图

    求最大密度子图 记得在最后一次寻找的时候记得将进入的边放大那么一点点,这样有利于当每条边都满流的情况下会选择点 #include <iostream> #include <algor ...

  5. 【POJ3155】生活的艰辛Hard Life

    题面 Description ADN公司内部共 n个员工,员工之间可能曾经因为小事有了过节,总是闹矛盾.若员工u和员工 v有矛盾,用边(u, v)表示,共 m个矛盾.最近,ADN公司内部越来越不团结, ...

  6. poj分类 很好很有层次感。

    初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      ( ...

  7. 【转】POJ题目分类推荐 (很好很有层次感)

    OJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094)初期: 一. ...

  8. 【转】ACM训练计划

    [转] POJ推荐50题以及ACM训练方案 -- : 转载自 wade_wang 最终编辑 000lzl POJ 推荐50题 第一类 动态规划(至少6题, 和 必做) 和 (可贪心) (稍难) 第二类 ...

  9. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

随机推荐

  1. Unity3D连接真机调试教程,可抓断点

    源地址:http://www.unity蛮牛.com/thread-19586-1-1.html <ignore_js_op> 未标题-1.jpg (52.33 KB, 下载次数: 0) ...

  2. SQLServer数据类型与C#类型对照表

    这是我在开发多层体系结构时遇到的问题,由于VS.NET尚不支持各种数据类型的空值即null, 放入实体类中在各个层之间作为参数传递,所以经查询参考SQL Server 2000的联机丛书和.NET的M ...

  3. 快速排序法QuickSort

    /** * * @author Administrator * 功能:交换式排序之快速排序 */ package com.test1; import java.util.Calendar; publi ...

  4. MinGW 编译libwebsockets

    libwebsockets是一个轻量的纯C库,在这里尝试使用MinGW进行构建. 官网地址:http://libwebsockets.org/trac/libwebsockets下载地址:http:/ ...

  5. Android-相册效果(图片缩放 自由滑动)

    先上图: 很多时候 我们会有这么一个需求: 展示一组图片 每个Item的图片 可以自由拉伸 滑动 焦点不冲突 网上有很多实现方法 通过自定义Gallery和ImageView来实现 个人不是很推荐 在 ...

  6. 一行代码搞定Adapter

    15年Google I/O大会发不了三个重要支持库 >Material design (Android Support Design) >百分比布局:Percent support lib ...

  7. java.lang.IllegalStateException: Required view 'text1' with ID 2131492943 for field 'mText' was not found. If this view is optional add '@Nullable' annotation

    使用ButterKnife 8.2的时候遇到这个问题 很明显空指针问题 按照提示添加 import android.support.annotation.Nullable;@Nullable  造成原 ...

  8. STL总结之functor

    STL中仿函数是重要的组成部分.所谓的仿函数就是通过重载括号运算符实现的, 如下: STL库中都是泛型仿函数如小于操作: STL中定义了许多有用的操作,如less(小于), less_equal(小于 ...

  9. [BILL WEI]一些经常用到的SQL函数

    截取时间 --convert可以截取特点值 convert(varchar(10),getdate(),120) 截取2012-11-11 11:11:11 前10位,得到日期2012-11-11

  10. [Stephen]自定义SimpleAdapter

    作者:AngelDevil 出处:www.cnblogs.com/angeldevil 先看一下构造函数: public SimpleAdapter (Context context, List< ...