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<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl;
const ll MAXN = 1e6 + 10;
int n, sz = 0, ans[MAXN];
pair<pll, int> A[MAXN];
vector<int> vec, adj[MAXN];
inline ll Cross(pll x, pll y) {
return 1ll * x.X * y.Y - 1ll * x.Y * y.X;
}
inline bool cmp(int i, int j) {
return Cross(make_pair(A[0].X.X - A[i].X.X, A[0].X.Y - A[i].X.Y),
make_pair(A[0].X.X - A[j].X.X, A[0].X.Y - A[j].X.Y)) < 0;
}
void dfs(int v, int p, int l) {
ans[l] = v;
for (int u : adj[v])
if (u != p)
dfs(u, v, A[vec[sz++]].Y);
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i = 0; i < n; i++) {
ll x, y;
cin >> x >> y;
A[i] = {{x, y}, i};
}
for (int i = 1; i < n; i++)
vec.push_back(i);
sort(all(vec), cmp);
dfs(1, 0, 0);
for (int i = 0; i < n; i++)
cout << ans[i] << sep;
cout << endl;
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... |