Submission #750669

#TimeUsernameProblemLanguageResultExecution timeMemory
750669drdilyorDrawing (CEOI22_drawing)C++17
0 / 100
241 ms34704 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9; const ll infl = 1e18; mt19937 rng; using pt = pair<int,int>; bool ccw(pt A, pt B, pt C) { return (C.second-A.second) * (B.first-A.first) > (B.second-A.second) * (C.first-A.first); } bool intersect(pt A, pt B, pt C, pt D) { return ccw(A, C, D) != ccw(B, C, D) && ccw(A, B, C) != ccw(A, B, D); } int main() { int n; cin >> n; vector<vector<int>> adj(n); vector<pair<int,int>> pts(n); for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; u--;v--; adj[u].push_back(v); adj[v].push_back(u); } map<pair<int,int>, int> ix; for (auto& [x, y] : pts) cin >> x >> y; for (int i = 0; i < n; i++) ix[pts[i]]= i; vector<int> res(n, -1); while (true) { vector<pt> hull; sort(pts.begin(), pts.end()); for (int i = 0; i < (int)pts.size();i ++) { while (hull.size() >= 2) { if (!ccw(hull.end()[-2], hull.end()[-1], pts[i])) hull.pop_back(); else break; } hull.push_back(pts[i]); } auto down = hull; hull = {}; for (int i = (int)pts.size()-1; i >= 0; i--) { while (hull.size() >= 2) { if (!ccw(hull.end()[-2], hull.end()[-1], pts[i])) hull.pop_back(); else break; } hull.push_back(pts[i]); } for (int i = 1; i < (int)down.size()-1; i++) { hull.push_back(down[i]); } auto dfs = [&](auto& dfs, int i, int p)->void{ res[i] = ix[hull.back()]; hull.pop_back(); for (int e : adj[i]) { if (e == p) continue; dfs(dfs, e, i); } }; dfs(dfs, 0, -1); break; } for (int i : res) { assert(i >= 0); cout << i+1 << ' '; } cout << '\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...