#include #include #include using namespace std; using ll = long long; struct pont { int x, y; int id; }; int sgn(ll x) { return x > 0 ? 1 : x < 0 ? -1 : 0; } int fordul(ll Ax, ll Ay, ll Bx, ll By) { return sgn(Ax * By - Ay * Bx); } int fordul(const pont& A, const pont& O, const pont& B) { return fordul(A.x - O.x, A.y - O.y, B.x - O.x, B.y - O.y); } struct csucs { vector hova; int csszam = 0; }; int szamol(csucs* cs, csucs* el) { if(el) { cs->hova.erase(find(cs->hova.begin(), cs->hova.end(), el)); } int er = 0; for(csucs* cs2 : cs->hova) { er += szamol(cs2, cs); } return cs->csszam = er + 1; } void megold(pont* p1, pont* p2, csucs* cs) { auto fr = [p1](const pont& A, const pont& B) {return fordul(A, *p1, B) == 1;}; sort(p1 + 1, p2, fr); pont* p = p1 + 1; for(csucs* cs2 : cs->hova) { cout << p1->id << " " << p->id << "\n"; megold(p, p + cs2->csszam, cs2); p += cs2->csszam; } } int main() { ios::sync_with_stdio(false); int N; cin >> N; vector csucsok(N); for(int i = 0; i < N - 1; i++) { int a, b; cin >> a >> b; csucsok[a].hova.push_back(&csucsok[b]); csucsok[b].hova.push_back(&csucsok[a]); } szamol(&csucsok[0], nullptr); vector pontok(N); for(int i = 0; i < N; i++) { cin >> pontok[i].x >> pontok[i].y; pontok[i].id = i; } auto xyr = [](const pont& p1, const pont& p2) { return make_pair(p1.x, p1.y) < make_pair(p2.x, p2.y); }; auto minit = min_element(pontok.begin(), pontok.end(), xyr); swap(*minit, *pontok.begin()); megold(&pontok[0], &pontok[0] + N, &csucsok[0]); }