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 real()
#define Y imag()
using namespace std;
using ll = long long;
using P = complex<ll>;
const int N = 200200;
vector<int> adj[N];
vector<int> ord;
pair<P, int> pt[N];
bool cmp1(P a, P b) {
if (a.X != b.X) return a.X < b.X;
else return a.Y < b.Y;
}
bool cmp2(pair<P, int> a, pair<P, int> b) {
return (conj(b.first - a.first) * (a.first - pt[0].first)).Y > 0;
}
void dfs(int u, int p) {
vector<int> ch;
for (int v : adj[u]) if (v != p) ch.push_back(v);
if (ch.size() == 0) ord.push_back(u);
else if (ch.size() == 1) {
ord.push_back(u);
dfs(ch[0], u);
} else {
dfs(ch[0], u);
ord.push_back(u);
dfs(ch[1], u);
}
}
void solve() {
int n;
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);
}
int r = 1;
while (adj[r].size() > 1) ++r;
dfs(r, -1);
for (int i = 0; i < n; ++i) {
int x, y;
cin >> x >> y;
pt[i] = {{x, y}, i};
if (cmp1(pt[i].first, pt[0].first)) swap(pt[i], pt[0]);
}
sort(pt+1, pt+n, cmp2);
vector<int> ans(n);
for (int i = 0; i < n; ++i) ans[pt[i].second] = ord[i];
for (int i = 0; i < n; ++i) cout << ans[i] << " \n"[i == n-1];
}
int main() {
cin.tie(0) -> sync_with_stdio(0);
solve();
}
# | 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... |