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;
struct Point {
int X, Y, id;
bool operator<(const Point& p) const {
if (X != p.X) return X < p.X;
return Y < p.Y;
}
};
const int NN = 1e6 + 10;
vector<int> G[NN];
Point Ps[NN];
int N, Ans[NN];
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);
}
bool cmp(const Point& a, const Point& b) { return cross(Ps[0], a, b) >= 0; }
void dfs(int u, int fa, int& pi) {
Ans[u] = Ps[pi++].id;
for (int v : G[u])
if (v != fa) dfs(v, u, pi);
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
cin >> N;
for (int i = 1, a, b; i < N; i++)
cin >> a >> b, G[a].push_back(b), G[b].push_back(a);
for (int i = 0, x, y; i < N; i++) cin >> x >> y, Ps[i] = {x, y, i + 1};
sort(Ps, Ps + N), sort(Ps + 1, Ps + N, cmp);
int pi = 0;
dfs(1, 0, pi);
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... |