This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// CEOI 2022 Day2 Drawing
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
struct Point {
int x, y, id;
bool operator<(const Point& p) const {
if (x != p.x) return x < p.x;
return y < p.y;
}
};
LL cross(const Point& a, const Point& b, const Point& c) {
return (LL)a.x * (b.y - c.y) + (LL)b.x * (c.y - a.y) + (LL)c.x * (a.y - b.y);
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int N;
cin >> N;
vector<vector<int>> G(N + 1);
for (int i = 1, a, b; i < N; i++)
cin >> a >> b, G[a].push_back(b), G[b].push_back(a);
vector<Point> ps(N);
for (int i = 0; i < N; i++) cin >> ps[i].x >> ps[i].y, ps[i].id = i + 1;
sort(begin(ps), end(ps));
sort(begin(ps) + 1, end(ps),
[&](const Point& a, const Point& b) { return cross(ps[0], a, b) >= 0; });
int pi = 0;
vector<int> Ans(N + 1);
function<void(int, int)> dfs = [&](int u, int fa) {
Ans[u] = ps[pi++].id;
for (int v : G[u])
if (v != fa) dfs(v, u);
};
dfs(1, 0);
for (int i = 1; i <= N; i++) printf("%d ", Ans[i]);
puts("");
return 0;
}
# | 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... |