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>
#define X first
#define Y second
using namespace std;
typedef long long LL;
const int maxn = 1e6 + 10;
int n;
vector<int> G[maxn];
using Point = pair<int, int>;
pair<Point, int> Ps[maxn];
int Ans[maxn];
LL cross(Point a, Point b, 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 pair<Point, int>& a, const pair<Point, int>& b) {
return cross(Ps[0].X, a.X, b.X) >= 0;
}
void solve(int u, int fa, int& pi) {
Ans[u] = Ps[pi++].second;
for (int v : G[u])
if (v != fa) solve(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;
solve(1, 0, pi);
for (int i = 1; i <= n; i++) printf("%d ", Ans[i]);
printf("\n");
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... |