Submission #1089396

#TimeUsernameProblemLanguageResultExecution timeMemory
1089396hihihahPastiri (COI20_pastiri)C++14
0 / 100
232 ms40788 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); #define orz "mo" if(fopen(orz".inp", "r")){ freopen(orz".inp", "r", stdin); freopen(orz".out", "w", stdout); } 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:49:8: warning: unused variable 'res' [-Wunused-variable]
   49 |     ll res = 0;
      |        ^~~
pastiri.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(orz".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
pastiri.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen(orz".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...