////////////////////////////
// Gke vay sao //
////////////////////////////
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using ull = unsigned ll;
using ld = long double;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());
ll min(const ll &a, const ll &b){
return (a < b) ? a : b;
}
ll max(const ll &a, const ll &b){
return (a > b) ? a : b;
}
//const ll Mod = 1000000007;
//const ll Mod2 = 999999999989;
//only use when required
const int maxN = 1e5 + 1;
int n;
struct TPoint{
int x, y, idx;
};
TPoint p[maxN];
vector <int> adj[maxN];
int sz[maxN];
int ans[maxN];
int x, y;
void pre_dfs(int u, int par){
sz[u] = 1;
for (int i: adj[u]){
if (i == par) continue;
pre_dfs(i, u);
sz[u] += sz[i];
}
}
void dfs(int u, int par, int idx){
ans[p[idx].idx] = u;
int tem = idx + 1;
for (int i: adj[u]){
if (i == par) continue;
dfs(i, u, tem);
tem += sz[i];
}
}
void Init(){
cin >> n;
for (int i = 1; i < n; ++i){
int u, v; cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
pre_dfs(1, 0);
for (int i = 1; i <= n; ++i){
cin >> p[i].x >> p[i].y;
p[i].idx = i;
}
if (n == 1){
cout << 1; return;
}
sort(p + 1, p + n + 1,[](const auto &i, const auto &j){
//left bottom
if (i.x == j.x) return i.y < j.y;
return i.x < j.x;
});
x = p[1].x;
y = p[1].y;
sort(p + 2, p + n + 1,[&](const auto &i, const auto &j){
//cross product
return x * i.y - i.x * y > x * j.y - j.x * y;
});
dfs(1, 0, 1);
for (int i = 1; i <= n; ++i) cout << ans[i] << " ";
}
#define debu
#define taskname "test"
signed main(){
if (fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
#ifdef debug
freopen(taskname".out", "w", stdout);
#endif
}
faster;
ll tt = 1;
//cin >> tt;
while (tt--){
Init();
}
#ifdef debug
ofstream timeout("timeout.txt");
timeout << signed(1000 * double(clock()) / CLOCKS_PER_SEC);
timeout.close();
#else
cerr << "\nTime elapsed: " << 1000 * double(clock()) / CLOCKS_PER_SEC << "ms\n";
#endif
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:97:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
97 | freopen(taskname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
42 ms |
16680 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3028 KB |
Output is correct |
2 |
Correct |
5 ms |
3028 KB |
Output is correct |
3 |
Correct |
4 ms |
3028 KB |
Output is correct |
4 |
Correct |
4 ms |
3124 KB |
Output is correct |
5 |
Correct |
4 ms |
3156 KB |
Output is correct |
6 |
Correct |
4 ms |
3028 KB |
Output is correct |
7 |
Correct |
4 ms |
3008 KB |
Output is correct |
8 |
Correct |
4 ms |
3028 KB |
Output is correct |
9 |
Correct |
4 ms |
3156 KB |
Output is correct |
10 |
Correct |
4 ms |
3028 KB |
Output is correct |
11 |
Correct |
4 ms |
3156 KB |
Output is correct |
12 |
Correct |
6 ms |
3028 KB |
Output is correct |
13 |
Correct |
4 ms |
3028 KB |
Output is correct |
14 |
Correct |
4 ms |
3028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3028 KB |
Output is correct |
2 |
Correct |
5 ms |
3028 KB |
Output is correct |
3 |
Correct |
4 ms |
3028 KB |
Output is correct |
4 |
Correct |
4 ms |
3124 KB |
Output is correct |
5 |
Correct |
4 ms |
3156 KB |
Output is correct |
6 |
Correct |
4 ms |
3028 KB |
Output is correct |
7 |
Correct |
4 ms |
3008 KB |
Output is correct |
8 |
Correct |
4 ms |
3028 KB |
Output is correct |
9 |
Correct |
4 ms |
3156 KB |
Output is correct |
10 |
Correct |
4 ms |
3028 KB |
Output is correct |
11 |
Correct |
4 ms |
3156 KB |
Output is correct |
12 |
Correct |
6 ms |
3028 KB |
Output is correct |
13 |
Correct |
4 ms |
3028 KB |
Output is correct |
14 |
Correct |
4 ms |
3028 KB |
Output is correct |
15 |
Correct |
9 ms |
3540 KB |
Output is correct |
16 |
Correct |
8 ms |
3796 KB |
Output is correct |
17 |
Correct |
7 ms |
3668 KB |
Output is correct |
18 |
Correct |
8 ms |
4012 KB |
Output is correct |
19 |
Correct |
8 ms |
3928 KB |
Output is correct |
20 |
Correct |
9 ms |
3584 KB |
Output is correct |
21 |
Correct |
8 ms |
3540 KB |
Output is correct |
22 |
Correct |
8 ms |
3540 KB |
Output is correct |
23 |
Correct |
8 ms |
3716 KB |
Output is correct |
24 |
Correct |
9 ms |
3668 KB |
Output is correct |
25 |
Correct |
12 ms |
3892 KB |
Output is correct |
26 |
Correct |
9 ms |
3924 KB |
Output is correct |
27 |
Correct |
8 ms |
3540 KB |
Output is correct |
28 |
Correct |
8 ms |
3540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3028 KB |
Output is correct |
2 |
Correct |
5 ms |
3028 KB |
Output is correct |
3 |
Correct |
4 ms |
3028 KB |
Output is correct |
4 |
Correct |
4 ms |
3124 KB |
Output is correct |
5 |
Correct |
4 ms |
3156 KB |
Output is correct |
6 |
Correct |
4 ms |
3028 KB |
Output is correct |
7 |
Correct |
4 ms |
3008 KB |
Output is correct |
8 |
Correct |
4 ms |
3028 KB |
Output is correct |
9 |
Correct |
4 ms |
3156 KB |
Output is correct |
10 |
Correct |
4 ms |
3028 KB |
Output is correct |
11 |
Correct |
4 ms |
3156 KB |
Output is correct |
12 |
Correct |
6 ms |
3028 KB |
Output is correct |
13 |
Correct |
4 ms |
3028 KB |
Output is correct |
14 |
Correct |
4 ms |
3028 KB |
Output is correct |
15 |
Correct |
9 ms |
3540 KB |
Output is correct |
16 |
Correct |
8 ms |
3796 KB |
Output is correct |
17 |
Correct |
7 ms |
3668 KB |
Output is correct |
18 |
Correct |
8 ms |
4012 KB |
Output is correct |
19 |
Correct |
8 ms |
3928 KB |
Output is correct |
20 |
Correct |
9 ms |
3584 KB |
Output is correct |
21 |
Correct |
8 ms |
3540 KB |
Output is correct |
22 |
Correct |
8 ms |
3540 KB |
Output is correct |
23 |
Correct |
8 ms |
3716 KB |
Output is correct |
24 |
Correct |
9 ms |
3668 KB |
Output is correct |
25 |
Correct |
12 ms |
3892 KB |
Output is correct |
26 |
Correct |
9 ms |
3924 KB |
Output is correct |
27 |
Correct |
8 ms |
3540 KB |
Output is correct |
28 |
Correct |
8 ms |
3540 KB |
Output is correct |
29 |
Correct |
68 ms |
9408 KB |
Output is correct |
30 |
Correct |
70 ms |
12192 KB |
Output is correct |
31 |
Correct |
66 ms |
11596 KB |
Output is correct |
32 |
Correct |
67 ms |
13304 KB |
Output is correct |
33 |
Correct |
73 ms |
12244 KB |
Output is correct |
34 |
Correct |
63 ms |
9692 KB |
Output is correct |
35 |
Correct |
65 ms |
9616 KB |
Output is correct |
36 |
Correct |
57 ms |
8524 KB |
Output is correct |
37 |
Correct |
71 ms |
11268 KB |
Output is correct |
38 |
Correct |
79 ms |
12020 KB |
Output is correct |
39 |
Correct |
78 ms |
12252 KB |
Output is correct |
40 |
Correct |
75 ms |
11240 KB |
Output is correct |
41 |
Correct |
56 ms |
8680 KB |
Output is correct |
42 |
Correct |
66 ms |
9532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
42 ms |
16680 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |