Skip to content

Instantly share code, notes, and snippets.

@estelabn
Created July 14, 2023 13:55
Show Gist options
  • Save estelabn/1abfe897e3c2d639f1e4a32e9404a318 to your computer and use it in GitHub Desktop.
Save estelabn/1abfe897e3c2d639f1e4a32e9404a318 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin >> n >> m;
int k; cin >> k;
priority_queue<ii> q;
vector<int> vis(n,-1);
vector<vector<int>> v(n);
for(int i=0; i<m; i++){
int a,b; cin >> a >> b;
a--;b--;
v[b].push_back(a); v[a].push_back(b);
}
for(int i=0; i<k; i++){
int p, h;
cin >> p >> h;
p--;
vis[p] = h;
q.push({h,p});
}
while(!q.empty()){
auto [h,p] = q.top(); q.pop();
if(vis[p] > h) continue;
if(h == 0) continue;
h--;
for(auto i: v[p]){
if(vis[i] < h){
vis[i] = h;
q.push({h,i});
}
}
}
int cont = 0;
int ok = 0;
for(int i=0; i<n; i++) if(vis[i] > -1) cont++;
cout << cont << endl;
for(int i=0; i<n; i++){
if(vis[i] > -1){
if(ok) cout << ' ';
cout << i+1;
ok = 1;
}
}
cout << '\n';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment