이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
vector<vector<int>> g;
set<int> vis;
constexpr int inf = 1e9;
struct point {
    int x, y;
    point(int x, int y) : x(x), y(y) {}
    point() = default;
    point operator-(point other) {
        return {x - other.x,y - other.y};
    }
    int operator*(point other) {
        return x * other.y - y * other.x;
    }
};
vector<point> m;
vector<pair<point,int>> points;
vector<int> ans;
// 1 to 2, 2 to 3
int getAngle(point p1, point p2, point p3) {
    return (p3 - p1) * (p2 - p1);
}
//1
//5
//2
//6
//3
//4
void solve(int x, int par) {
    auto prev = m[par];
    for (auto child : g[x]) {
        if (par == child) continue;
        int sel = -1;
        int selId = -1;
        {
            auto i = *vis.begin();
            auto [p,id] = points[i];
            int ang = getAngle(m[x],p,points[sel == -1 ? 0 : sel].first);
            if (ang > 0 || sel == -1) {
                sel = i;
                selId = id;
            }
        }
        m[child] = points[sel].first;
        vis.erase(sel);
        ans[selId] = child;
        solve(child,x);
    }
}
point leftSide;
bool comp(pair<point,int> a, pair<point,int> b) {
    return getAngle(leftSide,a.first,b.first) > 0;
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n; cin >> n;
    g.resize(n + 1);
    for (int i = 0; i < n - 1; ++i) {
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    points.resize(n);
    int bestP = 0;
    for (int i = 0; i < n; ++i) {
        int x, y; cin >> x >> y;
        points[i] = {{x, y},i};
        if (points[bestP].first.x > x) {
            bestP = i;
        }
        if (points[bestP].first.x == x && points[bestP].first.y < y) {
            bestP = i;
        }
    }
    for (int i = 0; i < n; ++i) {
        vis.insert(i);
    }
    m.resize(n + 1);
    leftSide = points[bestP].first;
    sort(points.begin(),points.end(),comp);
    int j = 0;
    for (auto [p, i] : points) {
        if (points[bestP].first.x > p.x) {
            bestP =j;
        }
        if (points[bestP].first.x == p.x && points[bestP].first.y < p.x) {
            bestP = j;
        }
        j++;
    }
    m[0] = {0,0};
    m[1] = leftSide;
    vis.erase(bestP);
    ans.resize(n + 1);
    ans[points[bestP].second] = 1;
    solve(1,0);
    for (int i = 0; i < n; ++i) {
        cout << ans[i] << "\n";
    }
    return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'void solve(int, int)':
Main.cpp:39:10: warning: variable 'prev' set but not used [-Wunused-but-set-variable]
   39 |     auto prev = m[par];
      |          ^~~~| # | 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... |