# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
863533 | 2023-10-20T14:28:38 Z | Rifal | Pastiri (COI20_pastiri) | C++14 | 244 ms | 41556 KB |
#include <bits/stdc++.h> #include <fstream> #define endl '\n' #define mod 1000000007 #define INF 900000000 //#define cin fin //#define cout fout //#define fi first //#define se second using namespace std; //ofstream fout("intel.out"); //ifstream fin("intel.in"); const int Max = 5e5 + 5; vector<int> v[Max]; bool ok[Max]; int arr[Max]; int cnt = 0; void dfs(int s, int p) { for(auto i : v[s]) { if(i != p) dfs(i,s); } arr[cnt] = s; cnt++; } int main() { ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0); int n, k; cin >> n >> k; for(int i = 0; i < n-1; i++) { int a, b; cin >> a >> b; v[a].push_back(b); v[b].push_back(a); } for(int i = 0; i < k; i++) { int x; cin >> x; ok[x] = 1; } dfs(1,0); vector<int> ans; pair<int,int> last = {-1,-1}; for(int i = 0; i < cnt; i++) { if(last.first != -1 && ok[arr[i]] == 1) { if((i-last.second)%2 == 0) { ans.push_back(arr[(i-last.second)/2]); last.first = -1; last.second = -1; } else { ans.push_back(last.first); last.first = arr[i]; last.second = i; } } else if(ok[arr[i]] == 1) { last.first = arr[i]; last.second = i; } } if(last.first != -1) { ans.push_back(last.first); } cout << ans.size() << endl; for(int i = 0; i < ans.size(); i++) cout << ans[i] << ' '; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 106 ms | 41436 KB | Output is correct |
2 | Incorrect | 104 ms | 41556 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 14428 KB | Sheep 3030 not protected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 14424 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 244 ms | 30548 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |