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 a, b;
point() {}
point(int a, int b) : a(a), b(b) {}
};
ll operator*(point a, point b) {
return a.a*b.b-a.b*b.a;
}
point operator-(point a, point b) {
return point(a.a-b.a, a.b-b.b);
}
point base;
bool operator<(point a, point b) {
return (a-base)*(b-base) > 0;
}
typedef pair<int, int> pii;
typedef pair<point, int> ppi;
const int MAXN = 2e5+5;
int n;
ppi points[MAXN];
vector<int> edges[MAXN];
int nxt = 0;
int ans[MAXN];
void dfs(int cur, int p = -1) {
ans[points[nxt++].second] = cur+1;
for (int e: edges[cur]) {
if (e == p) continue;
dfs(e, cur);
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n;
int lft = 0;
for (int i = 0; i < n-1; i++) {
int x, y; cin >> x >> y;
x--; y--;
edges[x].push_back(y);
edges[y].push_back(x);
}
for (int i = 0; i < n; i++) {
int x, y; cin >> x >> y;
points[i] = ppi(point(x, y), i);
if (pii(x, y) < pii(points[lft].first.a, points[lft].first.b)) lft = i;
}
swap(points[0], points[lft]);
base = points[0].first;
sort(points+1, points+n);
dfs(0);
for (int i = 0; i < n; i++) {
if (i) cout << ' ';
cout << ans[i];
}
cout << '\n';
}
# | 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... |