#include #include #include #include #include #include #include #include #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define REP(i,n) FOR(i,0,n) #define TRACE(x) cerr << #x << " = " << x << endl #define _ << " _ " << #define pb push_back #define X first #define Y second using namespace std; typedef long long ll; typedef pair pii; int n; vector E[1005]; pii pts[1005]; int dfs(int id, int par){ int sol = 1; for (auto nxt : E[id]) if (par != nxt) sol += dfs(nxt, id); return sol; } // ind is for pts int solve(int id, int par, vector ind){ int i = ind[0]; for (auto t : ind) if (pts[t] < pts[i]) i = t; sort(ind.begin(), ind.end(), [i](int a, int b){ if (a == i) return true; if (b == i) return false; if (pts[a].X == pts[i].X) return true; if (pts[b].X == pts[i].X) return false; return (ll)(pts[a].Y - pts[i].Y) * (pts[b].X - pts[i].X) > (ll)(pts[b].Y - pts[i].Y) * (pts[a].X - pts[i].X); }); int curr = 1; for (auto nxt : E[id]) if (nxt != par){ int sz = dfs(nxt, id); int root = solve(nxt, id, vector(ind.begin() + curr, ind.begin() + curr + sz)); cout << i << " " << root << endl; curr += sz; } return i; } int main(){ ios_base::sync_with_stdio(false); cin >> n; REP(i,n-1){int a, b; cin >> a >> b; E[a].pb(b); E[b].pb(a);} REP(i,n) cin >> pts[i].X >> pts[i].Y; vector ind; REP(i,n) ind.pb(i); solve(0, 0, ind); return 0; }