# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
863536 | Rifal | Pastiri (COI20_pastiri) | C++14 | 293 ms | 52672 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |