-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD.cpp
84 lines (80 loc) · 1.48 KB
/
D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "bits/stdc++.h"
using namespace std;
vector <int> g[100010];
bool bad[100010];
int cnt[100010];
int deg[100010];
bool del[100010];
struct data {
int node;
double val;
data (int node, double val) : node(node), val(val) {}
data () {}
bool operator < (data x) const {
return val > x.val;
}
};
int main(int argc, char const *argv[])
{
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
for(int i = 1; i <= k; i++) {
int x;
scanf("%d", &x);
bad[x] = true;
del[x] = true;
}
for(int i = 1; i <= m; i++) {
int p, q;
scanf("%d %d", &p, &q);
assert(p != q);
g[p].emplace_back(q);
g[q].emplace_back(p);
}
priority_queue <data> Q;
for(int i = 1; i <= n; i++) {
if(bad[i]) {
continue;
}
for(auto j : g[i]) {
if(!bad[j]) ++cnt[i];
}
deg[i] = g[i].size();
Q.push(data(i, ((double) cnt[i]) / deg[i]));
}
vector <data> v;
while(!Q.empty()) {
int node = Q.top().node;
double val = Q.top().val;
Q.pop();
if(bad[node]) continue;
for(auto j : g[node]) {
if(bad[j]) continue;
--cnt[j];
Q.push(data(j, ((double) cnt[j]) / deg[j]));
}
bad[node] = true;
v.emplace_back(node, val);
}
int opt = -1;
for(int i = 0; i < v.size(); i++) {
if(opt == -1 || v[i].val > v[opt].val) {
opt = i;
}
}
for(int i = 0; i < opt; i++) {
del[v[i].node] = true;
}
vector <int> out;
for(int i = 1; i <= n; i++) {
if(!del[i]) {
out.emplace_back(i);
}
}
printf("%u\n", out.size());
for(auto i : out) {
printf("%d ", i);
}
printf("\n");
return 0;
}