Submission #698409

#TimeUsernameProblemLanguageResultExecution timeMemory
698409vjudge1Drawing (CEOI22_drawing)C++14
100 / 100
260 ms39628 KiB
#include <bits/stdc++.h> #define X first #define Y second using namespace std; typedef long long LL; struct Point { int X, Y, id; bool operator<(const Point& p) const { if (X != p.X) return X < p.X; return Y < p.Y; } }; const int maxn = 1e6 + 10; int n; vector<int> G[maxn]; // using Point = pair<int, int>; // pair<Point, int> Ps[maxn]; Point 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 Point& a, const Point& b) { return cross(Ps[0], a, b) >= 0; } void solve(int u, int fa, int& pi) { Ans[u] = Ps[pi++].id; 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...