Bare topic of the maximum density subgraph of POJ 3155

Source: Internet
Author: User
Tags integer numbers

Hard Life

Time Limit:8000 MS Memory Limit:65536 K
Total Submissions:6045 Accepted:1763
Case Time Limit:2000 MS 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 introducedHardness factorOf 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 peZ APIs? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> incubator/phn1yj40pc9zdiffusion + incubator/phn1yj41pc9zdiffusion + l1_vcd4kcjxwiggnsyxnzpq =" pst "> Input

The first line of the input file contains two integer numbersNAndM(1 ≤N≤ 100, 0 ≤M≤ 1000). HereNIs a total number of people in the company (people are numbered from 1N), And m is the number of pairs of people who work poorly in the same team. NextMLines describe those pairs with two integer numbersAiAndBi(1 ≤Ai,BiN,Ai=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 numberK(1 ≤KN)-The number of people in the hardest team, followedKLines 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 #15 61 55 44 22 51 23 1sample input #24 0

Sample Output

sample output #141245sample output #211

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.


For an undirected graph, select a subgraph with the highest density, that is, the maximum ratio of the number of edges to the number of points, and the vertex of the output subgraph,

Once you have read this question before the conference, please submit it to the ox:

Set wi to the number of sub-graph edges, and vi to the number of sub-graphs, that is, to use max {wi-ans * vi} ans as the binary value, consider by edge, if an edge is selected, the two endpoints connected to the edge will be selected, that is
The edge is also regarded as a vertex. The vertex weight is 1, and the original vertex weight is-ans. You can find the max weight closure graph to obtain the value of max, then let's go down the second part of the tree generated by the optimal ratio (this is an explanation)

Code:

/* ***********************************************Author :rabbitCreated Time :2014/3/8 16:40:10File Name :1718.cpp************************************************ */#pragma comment(linker, "/STACK:102400000,102400000")#include 
 
  #include 
  
   #include #include 
   
    #include 
    
     #include 
     
      #include 
      
       #include 
       
        #include 
        
         #include 
         
          #include 
          
           #include 
           
            #include 
            
             #include 
             using namespace std;#define INF 0x3f3f3f3f#define eps 1e-5#define pi acos(-1.0)typedef long long ll;const int maxn=1110;const int maxm=400010;struct Edge{int to,next;double cap;Edge(){};Edge(int _next,int _to,double _cap){next=_next;to=_to;cap=_cap;}}edge[maxm];int head[maxn],tol,dep[maxn],cur[maxn],n,m;void addedge(int u,int v,double flow){edge[tol]=Edge(head[u],v,flow);head[u]=tol++;edge[tol]=Edge(head[v],u,0);head[v]=tol++;}int Q[maxn];bool bfs(int start,int end){memset(dep,-1,sizeof(dep));int front=0,rear=0;dep[start]=0;Q[rear++]=start;while(front!=rear){int u=Q[front++];for(int i=head[u];i!=-1;i=edge[i].next){int v=edge[i].to;if(dep[v]==-1&&edge[i].cap>0){Q[rear++]=v,dep[v]=dep[u]+1;if(v==end)return 1;}}}return 0;}double dinic(int s,int t){ int i,top;double res=0; int S[maxn],cur[maxn]; while(bfs(s,t)){ memcpy(cur,head,sizeof(head)); int u=s;top=0; while(1){ if(u==t){ double min=INF;int loc; for(int i=0;i
              
               edge[S[i]].cap) min=edge[S[i]].cap,loc=i; for(int i=0;i
               
                0&&dep[u]+1==dep[edge[i].to])break; if(cur[u]!=-1)S[top++]=cur[u],u=edge[cur[u]].to; else{ if(top==0)break; dep[u]=-1;u=edge[S[--top]^1].to; } } } return res; } int start[1111],end[1111];double check(double mid){memset(head,-1,sizeof(head));tol=0;for(int i=1;i<=n;i++)addedge(i,n+m+1,mid);for(int i=1;i<=m;i++){addedge(0,n+i,1.0);addedge(n+i,start[i],INF);addedge(n+i,end[i],INF);}return m-dinic(0,n+m+1);}int fun(){ char ch;int flag=1,a=0; while(ch=getchar())if((ch>='0'&&ch<='9')||ch=='-')break; if(ch=='-')flag=-1;else a=ch-'0'; while(ch=getchar()){ if(ch>='0'&&ch<='9')a=10*a+ch-'0'; else break; } return flag*a;}int main(){while(~scanf("%d%d",&n,&m)){for(int i=1;i<=m;i++){start[i]=fun();end[i]=fun();}if(!m){puts("1\n1");continue;}double l=0,r=m;while(r-l>eps){double mid=(l+r)/2;double ret=check(mid);if(ret>0)l=mid;else r=mid;}//cout<<"hahha: "<
                
                 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.