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>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 5e5+5;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define fr first
#define sc second
int n, k, sheep[MAXN];
vector<int> edges[MAXN];
int main() {
cin >> n >> k;
for(int i = 1, a, b; i < n; i++) {
cin >> a >> b;
edges[a].pb(b);
edges[b].pb(a);
}
for(int i = 1; i <= k; i++)
cin >> sheep[i];
if(n==0) {
cout << "0\n";
}
else {
sort(sheep+1, sheep+1+k);
vector<int> ans;
for(int i = 1; i <= k; i++) {
if(i == k) {
ans.pb(sheep[i]);
break;
}
if((sheep[i+1] + sheep[i]) % 2 == 0)ans.pb((sheep[i+1] + sheep[i])/2), i++;
else ans.pb(sheep[i]);
}
cout << sz(ans) << "\n";
for(int it : ans) cout << it << " ";
}
}
# | 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... |