Submission #1089395

#TimeUsernameProblemLanguageResultExecution timeMemory
1089395hihihahPastiri (COI20_pastiri)C++17
0 / 100
256 ms41124 KiB
#include<bits/stdc++.h> #define ll long long #define pii pair<int, int> #define all(x) x.begin(), x.end(); using namespace std; const int N = 1e9 + 7; int n, k; vector<int> ke[500009]; int c[500009]; int dd[500009]; int vis[500009]; int trc[500009]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for(int i = 1; i < n; i ++){ int u, v; cin >> u >> v; ke[u].push_back(v); ke[v].push_back(u); } for(int i = 1; i <= k; i ++) cin >> c[i]; if(k == 1){ cout << 1; return 0; } queue<int> q; for(int i = 1; i <= k; i ++){ q.push(c[i]); vis[c[i]] = 1; dd[c[i]] = 1; trc[c[i]] = c[i]; } ll res = 0; while(q.size()){ int u = q.front(); q.pop(); for(int i : ke[u]) if(i != trc[u]){ if(!dd[i]){ vis[i] = vis[u]; dd[i] = dd[u] + 1; q.push(i); } else if(dd[i] == dd[u] + 1) vis[i] += vis[u]; } } vector<int> sav; for(int i = 1; i <= n; i ++) { if(ke[i].size() == 1 && vis[i] == 1) continue; int mx = 0; for(int j : ke[i]) mx = max(mx, dd[j]); if(dd[i] >= mx) sav.push_back(i); } cout << sav.size() << '\n'; for(int i : sav) cout << i << " "; }

Compilation message (stderr)

pastiri.cpp: In function 'int main()':
pastiri.cpp:43:8: warning: unused variable 'res' [-Wunused-variable]
   43 |     ll res = 0;
      |        ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...