This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long llint;
const int maxn = 1e6+10;
const int base = 31337;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;
int n;
vector< int > graph[maxn];
pair< pair<int, int>, int > niz[maxn];
int sol[maxn];
llint f(pair<int, int> a, pair<int, int> b) {
return (llint)a.X * b.Y - (llint)a.Y * b.X;
}
bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
return f(niz[0].X, a.X) > f(niz[0].X, b.X);
}
int t = 0;
void solve(int x, int parr) {
//printf("solve: %d\n", x);
sol[x] = niz[t++].Y;
for (int tren : graph[x]) {
if (tren == parr) continue;
solve(tren, x);
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i < n; i++) {
int a, b;
scanf("%d%d", &a, &b);
graph[a].push_back(b);
graph[b].push_back(a);
}
for (int i = 0; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
niz[i] = {{x, y}, i + 1};
}
sort(niz, niz+n);
sort(niz+1, niz+n, cmp);
//for (int i = 0; i < n; i++)
// printf("%d %d -- %d\n", niz[i].X.X, niz[i].X.Y, niz[i].Y);
solve(1, 0);
for (int i = 1; i <= n; i++) printf("%d ", sol[i]);
printf("\n");
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
Main.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | scanf("%d%d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | scanf("%d%d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |