#include "bits/stdc++.h" using namespace std; #define LL long long #define int LL #define PB push_back #define VI vector #define FOR(i,a,b) for(int i = (a); i <= (b); i++) #define REP(i,n) FOR(i, 0, (int)n - 1) #define PII pair #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define st first #define nd second template void mini(C & a4, C b4){a4 = min(a4, b4);} template void maxi(C & a4, C b4){a4 = max(a4, b4);} template void _dbg(const char * sdbg, TH h){ cerr< void _dbg(const char * sdbg, TH h, TA... a){ while(*sdbg!=',') cerr<<*sdbg++; cerr<<'='< ostream & operator<<(ostream & os, vector V){ os<<"[";for(auto vv: V) os < ostream & operator<<(ostream & os , pair P){ return os << "(" << P.st <<","< graph; VI sz; int dfs(int x, int p){ int sc = 1; for(int a: graph[x]){ if(a == p) continue; sc += dfs(a, x); } return sz[x] = sc; } struct Point{ int x, y; int idx; }; Point & operator -=(Point & lhs, Point rhs){ lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; } ostream & operator <<(ostream & os, Point lhs){ return os <<"("< ans; void sortPts(vector & pts, Point cur){ if(pts.empty()){ return; } vector left; vector right; Point pivot = pts.back(); pts.pop_back(); pivot -= cur; for(Point p: pts){ p -= cur; if(crossProd(p, pivot) < 0){ left.PB(p); } else{ right.PB(p); } } sort(ALL(left), [&](Point lhs, Point rhs){ lhs -= cur; rhs -= cur; return crossProd(lhs, rhs) < 0; }); sort(ALL(right), [&](Point lhs, Point rhs){ lhs -= cur; rhs -= cur; return crossProd(lhs, rhs) < 0; }); pivot.x += cur.x; pivot.y += cur.y; left.PB(pivot); left.insert(left.end(), ALL(right)); pts = left; } int tup(int x, int p, vector pts, Point father){ debug(x, p, pts, father); if(x != 0) sort(ALL(pts), [&](Point lhs, Point rhs){ return dist(lhs, father) > dist(rhs, father); }); Point cur = pts.back(); pts.pop_back(); sortPts(pts, cur); for(int a: graph[x]){ if(a == p) continue; vector acc(pts.end() - sz[a], pts.end()); pts.resize(SZ(pts) - sz[a]); int his = tup(a, x, acc, cur); ans.PB({cur.idx, his}); } return cur.idx; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; graph.resize(n); sz.resize(n); REP(i, n - 1){ int a,b; cin>>a>>b; graph[a].PB(b); graph[b].PB(a); } vector pts(n); REP(i, n){ int x,y; cin>>x>>y; pts[i] = {x, y, i}; } dfs(0, -1); tup(0, -1, pts, Point{0,0,-1}); for(PII p: ans){ cout<