Submission #701090

#TimeUsernameProblemLanguageResultExecution timeMemory
701090PurpleCrayonDrawing (CEOI22_drawing)C++17
100 / 100
247 ms29064 KiB
#include <bits/stdc++.h> using namespace std; #define sz(v) int(v.size()) #define ar array typedef long long ll; const int N = 2e5+10, MOD = 998244353; struct P { int x, y; int id; void read() { cin >> x >> y; } bool operator < (const P& he) const { return make_pair(x, y) < make_pair(he.x, he.y); } }; int n, sub[N], ans[N]; vector<int> adj[N]; int dfs_sub(int c, int p) { sub[c] = 1; for (int nxt : adj[c]) if (nxt != p) sub[c] += dfs_sub(nxt, c); return sub[c]; } int get_sub(int c) { return c == -1 ? 0 : sub[c]; } void dfs(int c, int p, int l, int r, vector<P>& pts) { int one = -1, two = -1; for (int nxt : adj[c]) if (nxt != p) { if (one == -1) one = nxt; else two = nxt; } if (get_sub(one) > get_sub(two)) swap(one, two); int m = l + get_sub(one); ans[m] = c; if (two == -1) return; if (one == -1) { dfs(two, c, m + 1, r, pts); } else { dfs(one, c, l, m - 1, pts); dfs(two, c, m + 1, r, pts); } } void solve() { cin >> n; for (int i = 0; i < n-1; i++) { int a, b; cin >> a >> b, --a, --b; adj[a].push_back(b), adj[b].push_back(a); } int root = -1; for (int i = 0; i < n; i++) if (sz(adj[i]) == 1) root = i; dfs_sub(root, -1); vector<P> pts(n); for (int i = 0; i < n; i++) { pts[i].read(); pts[i].id = i; } sort(pts.begin(), pts.end()); dfs(root, -1, 0, n-1, pts); for (int i = 0; i < n; i++) cout << ans[i]+1 << ' '; cout << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0); int T = 1; // cin >> T; while (T--) solve(); }
#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...