Codeforces 553D nudist Beach (graph theory, greed)

Source: Internet
Author: User

Solution:

Suppose you have selected all the points.

If you delete a point from it, the score for all other points can only be reduced or unchanged.

If you want to make the smallest score larger after several steps have been removed, then the point set that is deleted must contain the point with the lowest current score.

So each time a point is deleted, the maximum value is recorded once. It is good to take the maximum output of the case.

#include <bits/stdc++.h>using namespacestd;Const intN =100009; Vector<int> E[n], out;Set<pair<Double,int>>s;intDeg[n], vis[n], dg[n];intN, M, K;intMain () {Ios::sync_with_stdio (0 ); CIN>> n >> M >>K;  for(inti =1, X; I <= K; ++i) {cin>>x; VIS[X]=1; }     for(inti =1, u, v; I <= m; ++i) {cin>> u >>v; E[u].push_back (v),++Deg[u]; if(!vis[v]) + +Dg[u]; E[v].push_back (u),++Deg[v]; if(!vis[u]) + +Dg[v]; }     for(inti =1; I <= N; ++i) {if(!Vis[i]) S.insert (Make_pair (1. *dg[i]/Deg[i], i)); }    DoubleAns =-1;  while(!S.empty ()) {Auto It= *S.begin (); if(It.first >ans) {ans=It.first;  out. Clear ();  for(Auto &i:s) { out. push_back (I.second);        }} s.erase (S.begin ()); Vis[it.second]=1;  for(Auto &I:e[it.second]) {            if(!Vis[i]) {S.erase (Make_pair (1. *dg[i]/Deg[i], i)); --Dg[i]; S.insert (Make_pair (1. *dg[i]/Deg[i], i)); } }} cout<< out. Size () <<Endl;  for(Auto &i: out) {cout<< I <<" "; }}
View Code

Codeforces 553D nudist Beach (graph theory, greed)

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.