#include using namespace std; using ll = long long; struct xy { ll x,y,label; xy(int xi, int yi) : x(xi), y(yi) {} xy() {} ll norm() const { return x*x + y*y; } bool operator<(const xy& oth) { if(x!=oth.x) return x 0; return a.norm() < b.norm(); } }; struct ShiftedAngleCmp { AngleCmp cmp; xy first; ShiftedAngleCmp(const xy& root_, const xy& first_) : cmp(AngleCmp(root_)), first(first_) {} bool operator()(const xy& a, const xy& b) const { int cmpFirst = int(cmp(a, first)) - cmp(b, first); if(cmpFirst) return cmpFirst < 0; return cmp(a, b); } }; #define ALL(c) (c).begin(), (c).end() using vi = vector; using pii = pair; constexpr int N = 1000; vector ans; vector g[N]; int parent[N], sz[N]; vector all; void comp(int u, int p) { parent[u] = p; sz[u] = 1; for(int v : g[u]) if(v != p) { comp(v, u); sz[u] += sz[v]; } } void solve(int label, int v, vector vec, xy fst) { assert(vec.size() + 1 == sz[v]); sort(ALL(vec), ShiftedAngleCmp(all[label], fst)); int cur = 0; for(int u : g[v]) if(u != parent[v]) { cur += sz[u]; ans.push_back({label, vec[cur - 1].label}); solve(vec[cur-1].label, u, vector(vec.begin() + cur - sz[u], vec.begin() + cur - 1), all[label]); } assert(cur == vec.size()); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; for(int i=1;i>u>>v; g[u].push_back(v); g[v].push_back(u); } comp(0,-1); all.resize(n); for(int i=0;i>all[i].x>>all[i].y; all[i].label = i; } auto x = min_element(ALL(all)); xy root = *x; auto dupa = all; dupa.erase(dupa.begin() + (x - all.begin())); solve(root.label, 0, dupa, root - xy(0,1)); assert(ans.size() + 1 == n); for(const auto& p : ans) cout << p.first << ' ' << p.second << '\n'; }