////////////////////////////
// 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 = 3e5 + 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 |
Correct |
107 ms |
18656 KB |
Output is correct |
2 |
Correct |
133 ms |
23408 KB |
Output is correct |
3 |
Correct |
124 ms |
21328 KB |
Output is correct |
4 |
Correct |
141 ms |
24284 KB |
Output is correct |
5 |
Correct |
137 ms |
24588 KB |
Output is correct |
6 |
Correct |
111 ms |
18880 KB |
Output is correct |
7 |
Correct |
140 ms |
19244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
7636 KB |
Output is correct |
2 |
Correct |
7 ms |
7764 KB |
Output is correct |
3 |
Correct |
7 ms |
7764 KB |
Output is correct |
4 |
Correct |
8 ms |
7836 KB |
Output is correct |
5 |
Correct |
8 ms |
7892 KB |
Output is correct |
6 |
Correct |
7 ms |
7636 KB |
Output is correct |
7 |
Correct |
6 ms |
7764 KB |
Output is correct |
8 |
Correct |
7 ms |
7736 KB |
Output is correct |
9 |
Correct |
6 ms |
7764 KB |
Output is correct |
10 |
Correct |
7 ms |
7764 KB |
Output is correct |
11 |
Correct |
7 ms |
7892 KB |
Output is correct |
12 |
Correct |
7 ms |
7764 KB |
Output is correct |
13 |
Correct |
6 ms |
7764 KB |
Output is correct |
14 |
Correct |
6 ms |
7764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
7636 KB |
Output is correct |
2 |
Correct |
7 ms |
7764 KB |
Output is correct |
3 |
Correct |
7 ms |
7764 KB |
Output is correct |
4 |
Correct |
8 ms |
7836 KB |
Output is correct |
5 |
Correct |
8 ms |
7892 KB |
Output is correct |
6 |
Correct |
7 ms |
7636 KB |
Output is correct |
7 |
Correct |
6 ms |
7764 KB |
Output is correct |
8 |
Correct |
7 ms |
7736 KB |
Output is correct |
9 |
Correct |
6 ms |
7764 KB |
Output is correct |
10 |
Correct |
7 ms |
7764 KB |
Output is correct |
11 |
Correct |
7 ms |
7892 KB |
Output is correct |
12 |
Correct |
7 ms |
7764 KB |
Output is correct |
13 |
Correct |
6 ms |
7764 KB |
Output is correct |
14 |
Correct |
6 ms |
7764 KB |
Output is correct |
15 |
Correct |
11 ms |
8232 KB |
Output is correct |
16 |
Correct |
11 ms |
8532 KB |
Output is correct |
17 |
Correct |
11 ms |
8408 KB |
Output is correct |
18 |
Correct |
10 ms |
8660 KB |
Output is correct |
19 |
Correct |
11 ms |
8660 KB |
Output is correct |
20 |
Correct |
11 ms |
8148 KB |
Output is correct |
21 |
Correct |
11 ms |
8296 KB |
Output is correct |
22 |
Correct |
15 ms |
8172 KB |
Output is correct |
23 |
Correct |
11 ms |
8404 KB |
Output is correct |
24 |
Correct |
14 ms |
8432 KB |
Output is correct |
25 |
Correct |
14 ms |
8660 KB |
Output is correct |
26 |
Correct |
11 ms |
8560 KB |
Output is correct |
27 |
Correct |
11 ms |
8152 KB |
Output is correct |
28 |
Correct |
11 ms |
8276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
7636 KB |
Output is correct |
2 |
Correct |
7 ms |
7764 KB |
Output is correct |
3 |
Correct |
7 ms |
7764 KB |
Output is correct |
4 |
Correct |
8 ms |
7836 KB |
Output is correct |
5 |
Correct |
8 ms |
7892 KB |
Output is correct |
6 |
Correct |
7 ms |
7636 KB |
Output is correct |
7 |
Correct |
6 ms |
7764 KB |
Output is correct |
8 |
Correct |
7 ms |
7736 KB |
Output is correct |
9 |
Correct |
6 ms |
7764 KB |
Output is correct |
10 |
Correct |
7 ms |
7764 KB |
Output is correct |
11 |
Correct |
7 ms |
7892 KB |
Output is correct |
12 |
Correct |
7 ms |
7764 KB |
Output is correct |
13 |
Correct |
6 ms |
7764 KB |
Output is correct |
14 |
Correct |
6 ms |
7764 KB |
Output is correct |
15 |
Correct |
11 ms |
8232 KB |
Output is correct |
16 |
Correct |
11 ms |
8532 KB |
Output is correct |
17 |
Correct |
11 ms |
8408 KB |
Output is correct |
18 |
Correct |
10 ms |
8660 KB |
Output is correct |
19 |
Correct |
11 ms |
8660 KB |
Output is correct |
20 |
Correct |
11 ms |
8148 KB |
Output is correct |
21 |
Correct |
11 ms |
8296 KB |
Output is correct |
22 |
Correct |
15 ms |
8172 KB |
Output is correct |
23 |
Correct |
11 ms |
8404 KB |
Output is correct |
24 |
Correct |
14 ms |
8432 KB |
Output is correct |
25 |
Correct |
14 ms |
8660 KB |
Output is correct |
26 |
Correct |
11 ms |
8560 KB |
Output is correct |
27 |
Correct |
11 ms |
8152 KB |
Output is correct |
28 |
Correct |
11 ms |
8276 KB |
Output is correct |
29 |
Correct |
67 ms |
14160 KB |
Output is correct |
30 |
Correct |
72 ms |
16980 KB |
Output is correct |
31 |
Correct |
76 ms |
16332 KB |
Output is correct |
32 |
Correct |
75 ms |
17948 KB |
Output is correct |
33 |
Correct |
76 ms |
16892 KB |
Output is correct |
34 |
Correct |
67 ms |
14432 KB |
Output is correct |
35 |
Correct |
79 ms |
14284 KB |
Output is correct |
36 |
Correct |
66 ms |
13132 KB |
Output is correct |
37 |
Correct |
96 ms |
16012 KB |
Output is correct |
38 |
Correct |
69 ms |
16712 KB |
Output is correct |
39 |
Correct |
80 ms |
16972 KB |
Output is correct |
40 |
Correct |
77 ms |
15984 KB |
Output is correct |
41 |
Correct |
62 ms |
13476 KB |
Output is correct |
42 |
Correct |
82 ms |
14220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
107 ms |
18656 KB |
Output is correct |
2 |
Correct |
133 ms |
23408 KB |
Output is correct |
3 |
Correct |
124 ms |
21328 KB |
Output is correct |
4 |
Correct |
141 ms |
24284 KB |
Output is correct |
5 |
Correct |
137 ms |
24588 KB |
Output is correct |
6 |
Correct |
111 ms |
18880 KB |
Output is correct |
7 |
Correct |
140 ms |
19244 KB |
Output is correct |
8 |
Correct |
7 ms |
7636 KB |
Output is correct |
9 |
Correct |
7 ms |
7764 KB |
Output is correct |
10 |
Correct |
7 ms |
7764 KB |
Output is correct |
11 |
Correct |
8 ms |
7836 KB |
Output is correct |
12 |
Correct |
8 ms |
7892 KB |
Output is correct |
13 |
Correct |
7 ms |
7636 KB |
Output is correct |
14 |
Correct |
6 ms |
7764 KB |
Output is correct |
15 |
Correct |
7 ms |
7736 KB |
Output is correct |
16 |
Correct |
6 ms |
7764 KB |
Output is correct |
17 |
Correct |
7 ms |
7764 KB |
Output is correct |
18 |
Correct |
7 ms |
7892 KB |
Output is correct |
19 |
Correct |
7 ms |
7764 KB |
Output is correct |
20 |
Correct |
6 ms |
7764 KB |
Output is correct |
21 |
Correct |
6 ms |
7764 KB |
Output is correct |
22 |
Correct |
11 ms |
8232 KB |
Output is correct |
23 |
Correct |
11 ms |
8532 KB |
Output is correct |
24 |
Correct |
11 ms |
8408 KB |
Output is correct |
25 |
Correct |
10 ms |
8660 KB |
Output is correct |
26 |
Correct |
11 ms |
8660 KB |
Output is correct |
27 |
Correct |
11 ms |
8148 KB |
Output is correct |
28 |
Correct |
11 ms |
8296 KB |
Output is correct |
29 |
Correct |
15 ms |
8172 KB |
Output is correct |
30 |
Correct |
11 ms |
8404 KB |
Output is correct |
31 |
Correct |
14 ms |
8432 KB |
Output is correct |
32 |
Correct |
14 ms |
8660 KB |
Output is correct |
33 |
Correct |
11 ms |
8560 KB |
Output is correct |
34 |
Correct |
11 ms |
8152 KB |
Output is correct |
35 |
Correct |
11 ms |
8276 KB |
Output is correct |
36 |
Correct |
67 ms |
14160 KB |
Output is correct |
37 |
Correct |
72 ms |
16980 KB |
Output is correct |
38 |
Correct |
76 ms |
16332 KB |
Output is correct |
39 |
Correct |
75 ms |
17948 KB |
Output is correct |
40 |
Correct |
76 ms |
16892 KB |
Output is correct |
41 |
Correct |
67 ms |
14432 KB |
Output is correct |
42 |
Correct |
79 ms |
14284 KB |
Output is correct |
43 |
Correct |
66 ms |
13132 KB |
Output is correct |
44 |
Correct |
96 ms |
16012 KB |
Output is correct |
45 |
Correct |
69 ms |
16712 KB |
Output is correct |
46 |
Correct |
80 ms |
16972 KB |
Output is correct |
47 |
Correct |
77 ms |
15984 KB |
Output is correct |
48 |
Correct |
62 ms |
13476 KB |
Output is correct |
49 |
Correct |
82 ms |
14220 KB |
Output is correct |
50 |
Correct |
170 ms |
19948 KB |
Output is correct |
51 |
Correct |
266 ms |
35104 KB |
Output is correct |
52 |
Correct |
284 ms |
32788 KB |
Output is correct |
53 |
Correct |
261 ms |
33616 KB |
Output is correct |
54 |
Correct |
262 ms |
38112 KB |
Output is correct |
55 |
Correct |
246 ms |
28464 KB |
Output is correct |
56 |
Correct |
282 ms |
27496 KB |
Output is correct |
57 |
Correct |
37 ms |
11556 KB |
Output is correct |
58 |
Correct |
262 ms |
32280 KB |
Output is correct |
59 |
Correct |
245 ms |
31660 KB |
Output is correct |
60 |
Correct |
252 ms |
38264 KB |
Output is correct |
61 |
Correct |
267 ms |
33064 KB |
Output is correct |
62 |
Correct |
47 ms |
11608 KB |
Output is correct |
63 |
Correct |
235 ms |
26720 KB |
Output is correct |