# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
863536 | 2023-10-20T14:34:07 Z | Rifal | Pastiri (COI20_pastiri) | C++14 | 293 ms | 52672 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 | 103 ms | 41552 KB | Output is correct |
2 | Correct | 132 ms | 41472 KB | Output is correct |
3 | Correct | 107 ms | 48080 KB | Output is correct |
4 | Correct | 146 ms | 52672 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 14428 KB | Sheep 3269 not protected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 14428 KB | Sheep 12 not protected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 293 ms | 30568 KB | Sheep 470 not protected |
2 | Halted | 0 ms | 0 KB | - |