# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
742890 | hmm789 | Drawing (CEOI22_drawing) | C++14 | 219 ms | 36964 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>
using namespace std;
#define int long long
vector<int> adj[200000];
vector<int> topo;
void dfs(int x, int p) {
for(int i : adj[x]) if(i != p) {
dfs(i, x);
}
topo.push_back(x);
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, x, y;
cin >> n;
for(int i = 0; i < n-1; i++) {
cin >> x >> y;
x--; y--;
adj[x].push_back(y);
adj[y].push_back(x);
}
dfs(0, -1);
reverse(topo.begin(), topo.end());
pair<pair<int, int>, int> pt[n];
int ans[n];
for(int i = 0; i < n; i++) {
cin >> pt[i].first.first >> pt[i].first.second;
pt[i].second = i;
}
sort(pt, pt+n);
vector<pair<pair<int, int>, int>> top, bottom;
top.push_back(pt[0]);
bottom.push_back(pt[0]);
int idx = -1;
for(int i = 1; i < n; i++) {
if(pt[i].first.second < bottom.back().first.second) bottom.push_back(pt[i]);
else if(pt[i].first.second > top.back().first.second) top.push_back(pt[i]);
else {
idx = i;
break;
}
}
for(int i = idx; i < n; i++) {
if(abs(pt[i].first.second-bottom.back().first.second) < abs(pt[i].first.second-top.back().first.second)) bottom.push_back(pt[i]);
else top.push_back(pt[i]);
}
for(int i = 0; i < n; i++) {
if(i < top.size()) {
ans[top[i].second] = topo[i];
} else {
ans[bottom[bottom.size()-1-(i-top.size())].second] = topo[i];
}
}
for(int i = 0; i < n; i++) cout << ans[i]+1 << " ";
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |