Codeforces 553 D Nudist Beach

Source: Internet
Author: User

Test instructions, presumably, gives a graph that ensures that at least one edge is on each point and at most one edge between any two points. It is obvious that this graph has many point sets, and if we define a weight for each point, then each point set has a minimum weight point, and now requires a point set, which is as large as possible for the minimum weight of the point set.
In a subset, the weight of the point is calculated by dividing the degree of the point in the sub-set by the degree of the point in the graph.
At first glance, it seems impossible.
It is obvious to know that each point in the graph of weights is easy to calculate, then we try to delete points, so that the current graph of the minimum weight of the weight of the value of the larger, it is clear to know to delete the minimum weight point, why? Because if you delete the sub-small weight point, if the sub-small weight points with the minimum weight point has a connecting edge, then the minimum weight point is the minimum weight point of the new figure. If there is no edge, the minimum weight point of the new graph is still unchanged. So it's possible to change the minimum weight point of the new graph only by deleting the least-weighted point, which will change the minimum weight of the new graph. So it is very obvious here, as long as each time the minimum weight of the current graph is deleted, then it is necessary to cite a new figure, the point set of the new map is the answer we want.
So this problem can be done, I was directly done two times delete, the first time to get the maximum minimum weight is how much, the second enumeration to a new graph of the minimum weight equals the maximum minimum weight, then it is obvious that the new map subset is the answer.

Maintain a small heap, the time complexity is 2 (n+m) log (n+m)


#include <map> #include <string> #include <cstring> #include <cstdio> #include <cstdlib># include<cmath> #include <queue> #include <vector> #include <iostream> #include <algorithm > #include <bitset> #include <climits> #include <list> #include <iomanip> #include <stack > #include <set>using namespace std;struct node{int no;double Val;node () {}node (int no,double val) {this->no= No;this->val=val;} BOOL operator < (node one) Const{return val>one.val;}}; Priority_queue<node>q[2];bool Fb[100010],dl[100010];vector<int>edge[100010];int d[100010][2],dd[ 100010];int Main () {int n,m,k;cin>>n>>m>>k;int sum=k;while (k--) {int t;cin>>t;fb[t]=1;} while (m--) {int a,b;cin>>a>>b;d[a][0]++;d [b][0]++;if (!fb[a]) d[b][1]++;if (!fb[b]) d[a][1]++;edge[a]. Push_back (b); Edge[b].push_back (a); Double mn=1e99;for (int i=1;i<=n;i++) if (!fb[i]) {Q[0].push (node (i,double (d[i][1))/d[i][0]), Mn=min (Mn,double (d[ i][1])/d[i][0]);} Q[1]=q[0];int flag=0;for (int i=0;i<2;i++) {memset (dl,0,sizeof (DL)); Memset (Dd,0,sizeof (DD)); if (i==1&& flag==0) Break;while (Q[i].size ()) {node t=q[i].top (); Q[i].pop (); if (dl[t.no]) continue;if (i==1) {if (T.no==flag) break ; sum++;} Dl[t.no]=1;if (i==0&&t.val>mn) {mn=t.val;flag=t.no;} for (int j=0;j<edge[t.no].size (); j + +) {int v=edge[t.no][j];if (dl[v]| | FB[V]) Continue;dd[v]++;q[i].push (Node (v,double (D[v][1]-dd[v])/d[v][0]);}}} cout<<n-sum<<endl;for (int i=1;i<=n;i++) if (!fb[i]&&!dl[i]) cout<<i<< "";}


Time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Nudist Beach is planning a military operation to attack the life fibers. In this operation, they would attack and capture several cities which is currently under the control of the life fibers.

There isNCities, labeled from 1 toN, andmBidirectional roads between them. Currently, there is life fibers in every city. In addition, there iskCities that is fortresses of the life fibers that cannot is captured under any circumstances. So, the nudist Beach can capture a arbitrary non-empty subset of cities with no fortresses.

After the operation, nudist Beach'll has to defend the captured cities from counterattack. If They capture a city and it's connected to many life Fiber controlled cities, it'll be easily defeated. So, nudist beach would like-to-capture a set of cities such that for each captured city the ratio of nudist Beach controll Ed neighbors among all neighbors of the is as high as possible.

More formally, they would like to capture a non-empty set of citiesSWith no fortresses of the life fibers. The strength of a city is defined as (number of neighbors ofxInchS)/(total number of neighbors ofx). Here, the cities is called neighbors if they is connnected with a road. The goal is to maximize the strength of the weakest city inS.

Given a description of the graph, and the cities with fortresses, find a non-empty subset that maximizes the strength of T He weakest city.

Input

The First line of input contains three integers  n ,? m ,? k   ( 2?? ≤?? n ?? ≤?100?000 ,  1?≤? m ? ≤?100?000 ,  1?≤? k ? ≤? n ?-? 1 ).

The second line of input contains k integers, representing the cities with fortresses. These cities would all be distinct.

The nextmLines contain the roads. TheI-th of these lines would have 2 integers ai,? b I (1?≤? a i,? b i? ≤? N , ai? ≠? b I ). Every city'll has at least one road adjacent to it.

There is no more than one road between each pair of the cities.

Output

The first line should contain a integer R, denoting the size of an optimum set (1?≤? R≤? N?-? k).

The second line should contain r integers and denoting the cities in the set. Cities follow in an arbitrary order. This line should is contain any of the cities with fortresses.

If There is multiple possible answers, print any of them.

Sample Test (s) input
9 8 43 9 6 81 21 31 41 52 62 72 82 9
Output
31 4 5
Input
10 8 22 91 32 94 55 66 77 88 1010 4
Output
81 5 4 8 10 6 3 7
Note

The first example case achieves a strength of the. No other subset is strictly better.

The second example case achieves a strength of 1. Note that the subset doesn ' t necessarily has to be connected.






Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces 553 D Nudist Beach

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.