#include <bits/stdc++.h>
using i64 = long long;
#ifdef DEBUG
#include "../../debug.h"
#else
#define debug(...) void(23)
#endif
constexpr int max_N = int(2E5) + 5;
int N;
int A[max_N], B[max_N], ans[max_N];
std::vector<int> adj[max_N];
int cur = 0;
std::vector<int> p;
void solve(int v) {
ans[v] = p[cur++];
for (auto u : adj[v]) {
adj[u].erase(std::find(adj[u].begin(), adj[u].end(), v));
solve(u);
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> N;
for (int i = 0; i < N - 1; ++i) {
int u, v;
std::cin >> u >> v;
--u, --v;
adj[u].emplace_back(v);
adj[v].emplace_back(u);
}
for (int i = 0; i < N; ++i) {
std::cin >> A[i] >> B[i];
++A[i], ++B[i];
}
p.assign(N, 0);
std::iota(p.begin(), p.end(), 0);
std::sort(p.begin(), p.end(), [&](auto lhs, auto rhs) {
return std::pair{A[lhs], B[lhs]} < std::pair{A[rhs], B[rhs]};
});
solve(0);
for (int i = 0; i < N; ++i) {
std::cout << ans[i] + 1 << " \n"[i == N - 1];
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
15332 KB |
Output is correct |
2 |
Correct |
113 ms |
19528 KB |
Output is correct |
3 |
Correct |
71 ms |
17736 KB |
Output is correct |
4 |
Correct |
106 ms |
21316 KB |
Output is correct |
5 |
Correct |
121 ms |
21284 KB |
Output is correct |
6 |
Correct |
93 ms |
15128 KB |
Output is correct |
7 |
Correct |
65 ms |
16028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5628 KB |
Output is correct |
2 |
Correct |
6 ms |
5456 KB |
Output is correct |
3 |
Correct |
5 ms |
5432 KB |
Output is correct |
4 |
Correct |
7 ms |
5456 KB |
Output is correct |
5 |
Correct |
6 ms |
5456 KB |
Output is correct |
6 |
Correct |
7 ms |
5456 KB |
Output is correct |
7 |
Correct |
5 ms |
6992 KB |
Output is correct |
8 |
Correct |
4 ms |
6992 KB |
Output is correct |
9 |
Correct |
4 ms |
7064 KB |
Output is correct |
10 |
Correct |
5 ms |
7080 KB |
Output is correct |
11 |
Correct |
7 ms |
5456 KB |
Output is correct |
12 |
Correct |
4 ms |
7080 KB |
Output is correct |
13 |
Correct |
4 ms |
5456 KB |
Output is correct |
14 |
Correct |
4 ms |
7160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5628 KB |
Output is correct |
2 |
Correct |
6 ms |
5456 KB |
Output is correct |
3 |
Correct |
5 ms |
5432 KB |
Output is correct |
4 |
Correct |
7 ms |
5456 KB |
Output is correct |
5 |
Correct |
6 ms |
5456 KB |
Output is correct |
6 |
Correct |
7 ms |
5456 KB |
Output is correct |
7 |
Correct |
5 ms |
6992 KB |
Output is correct |
8 |
Correct |
4 ms |
6992 KB |
Output is correct |
9 |
Correct |
4 ms |
7064 KB |
Output is correct |
10 |
Correct |
5 ms |
7080 KB |
Output is correct |
11 |
Correct |
7 ms |
5456 KB |
Output is correct |
12 |
Correct |
4 ms |
7080 KB |
Output is correct |
13 |
Correct |
4 ms |
5456 KB |
Output is correct |
14 |
Correct |
4 ms |
7160 KB |
Output is correct |
15 |
Correct |
11 ms |
7248 KB |
Output is correct |
16 |
Correct |
15 ms |
6396 KB |
Output is correct |
17 |
Correct |
8 ms |
5968 KB |
Output is correct |
18 |
Correct |
14 ms |
6480 KB |
Output is correct |
19 |
Correct |
9 ms |
7760 KB |
Output is correct |
20 |
Correct |
9 ms |
7248 KB |
Output is correct |
21 |
Correct |
13 ms |
6088 KB |
Output is correct |
22 |
Correct |
10 ms |
5968 KB |
Output is correct |
23 |
Correct |
8 ms |
7504 KB |
Output is correct |
24 |
Correct |
7 ms |
7504 KB |
Output is correct |
25 |
Correct |
12 ms |
6480 KB |
Output is correct |
26 |
Correct |
9 ms |
6224 KB |
Output is correct |
27 |
Correct |
10 ms |
5968 KB |
Output is correct |
28 |
Correct |
9 ms |
5968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5628 KB |
Output is correct |
2 |
Correct |
6 ms |
5456 KB |
Output is correct |
3 |
Correct |
5 ms |
5432 KB |
Output is correct |
4 |
Correct |
7 ms |
5456 KB |
Output is correct |
5 |
Correct |
6 ms |
5456 KB |
Output is correct |
6 |
Correct |
7 ms |
5456 KB |
Output is correct |
7 |
Correct |
5 ms |
6992 KB |
Output is correct |
8 |
Correct |
4 ms |
6992 KB |
Output is correct |
9 |
Correct |
4 ms |
7064 KB |
Output is correct |
10 |
Correct |
5 ms |
7080 KB |
Output is correct |
11 |
Correct |
7 ms |
5456 KB |
Output is correct |
12 |
Correct |
4 ms |
7080 KB |
Output is correct |
13 |
Correct |
4 ms |
5456 KB |
Output is correct |
14 |
Correct |
4 ms |
7160 KB |
Output is correct |
15 |
Correct |
11 ms |
7248 KB |
Output is correct |
16 |
Correct |
15 ms |
6396 KB |
Output is correct |
17 |
Correct |
8 ms |
5968 KB |
Output is correct |
18 |
Correct |
14 ms |
6480 KB |
Output is correct |
19 |
Correct |
9 ms |
7760 KB |
Output is correct |
20 |
Correct |
9 ms |
7248 KB |
Output is correct |
21 |
Correct |
13 ms |
6088 KB |
Output is correct |
22 |
Correct |
10 ms |
5968 KB |
Output is correct |
23 |
Correct |
8 ms |
7504 KB |
Output is correct |
24 |
Correct |
7 ms |
7504 KB |
Output is correct |
25 |
Correct |
12 ms |
6480 KB |
Output is correct |
26 |
Correct |
9 ms |
6224 KB |
Output is correct |
27 |
Correct |
10 ms |
5968 KB |
Output is correct |
28 |
Correct |
9 ms |
5968 KB |
Output is correct |
29 |
Correct |
70 ms |
11716 KB |
Output is correct |
30 |
Correct |
50 ms |
14920 KB |
Output is correct |
31 |
Correct |
76 ms |
13616 KB |
Output is correct |
32 |
Correct |
72 ms |
16968 KB |
Output is correct |
33 |
Correct |
48 ms |
15176 KB |
Output is correct |
34 |
Correct |
50 ms |
11848 KB |
Output is correct |
35 |
Correct |
80 ms |
13384 KB |
Output is correct |
36 |
Correct |
48 ms |
11848 KB |
Output is correct |
37 |
Correct |
51 ms |
14004 KB |
Output is correct |
38 |
Correct |
74 ms |
14900 KB |
Output is correct |
39 |
Correct |
61 ms |
15180 KB |
Output is correct |
40 |
Correct |
49 ms |
14928 KB |
Output is correct |
41 |
Correct |
46 ms |
11848 KB |
Output is correct |
42 |
Correct |
57 ms |
12696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
15332 KB |
Output is correct |
2 |
Correct |
113 ms |
19528 KB |
Output is correct |
3 |
Correct |
71 ms |
17736 KB |
Output is correct |
4 |
Correct |
106 ms |
21316 KB |
Output is correct |
5 |
Correct |
121 ms |
21284 KB |
Output is correct |
6 |
Correct |
93 ms |
15128 KB |
Output is correct |
7 |
Correct |
65 ms |
16028 KB |
Output is correct |
8 |
Correct |
4 ms |
5628 KB |
Output is correct |
9 |
Correct |
6 ms |
5456 KB |
Output is correct |
10 |
Correct |
5 ms |
5432 KB |
Output is correct |
11 |
Correct |
7 ms |
5456 KB |
Output is correct |
12 |
Correct |
6 ms |
5456 KB |
Output is correct |
13 |
Correct |
7 ms |
5456 KB |
Output is correct |
14 |
Correct |
5 ms |
6992 KB |
Output is correct |
15 |
Correct |
4 ms |
6992 KB |
Output is correct |
16 |
Correct |
4 ms |
7064 KB |
Output is correct |
17 |
Correct |
5 ms |
7080 KB |
Output is correct |
18 |
Correct |
7 ms |
5456 KB |
Output is correct |
19 |
Correct |
4 ms |
7080 KB |
Output is correct |
20 |
Correct |
4 ms |
5456 KB |
Output is correct |
21 |
Correct |
4 ms |
7160 KB |
Output is correct |
22 |
Correct |
11 ms |
7248 KB |
Output is correct |
23 |
Correct |
15 ms |
6396 KB |
Output is correct |
24 |
Correct |
8 ms |
5968 KB |
Output is correct |
25 |
Correct |
14 ms |
6480 KB |
Output is correct |
26 |
Correct |
9 ms |
7760 KB |
Output is correct |
27 |
Correct |
9 ms |
7248 KB |
Output is correct |
28 |
Correct |
13 ms |
6088 KB |
Output is correct |
29 |
Correct |
10 ms |
5968 KB |
Output is correct |
30 |
Correct |
8 ms |
7504 KB |
Output is correct |
31 |
Correct |
7 ms |
7504 KB |
Output is correct |
32 |
Correct |
12 ms |
6480 KB |
Output is correct |
33 |
Correct |
9 ms |
6224 KB |
Output is correct |
34 |
Correct |
10 ms |
5968 KB |
Output is correct |
35 |
Correct |
9 ms |
5968 KB |
Output is correct |
36 |
Correct |
70 ms |
11716 KB |
Output is correct |
37 |
Correct |
50 ms |
14920 KB |
Output is correct |
38 |
Correct |
76 ms |
13616 KB |
Output is correct |
39 |
Correct |
72 ms |
16968 KB |
Output is correct |
40 |
Correct |
48 ms |
15176 KB |
Output is correct |
41 |
Correct |
50 ms |
11848 KB |
Output is correct |
42 |
Correct |
80 ms |
13384 KB |
Output is correct |
43 |
Correct |
48 ms |
11848 KB |
Output is correct |
44 |
Correct |
51 ms |
14004 KB |
Output is correct |
45 |
Correct |
74 ms |
14900 KB |
Output is correct |
46 |
Correct |
61 ms |
15180 KB |
Output is correct |
47 |
Correct |
49 ms |
14928 KB |
Output is correct |
48 |
Correct |
46 ms |
11848 KB |
Output is correct |
49 |
Correct |
57 ms |
12696 KB |
Output is correct |
50 |
Correct |
101 ms |
15688 KB |
Output is correct |
51 |
Correct |
164 ms |
29596 KB |
Output is correct |
52 |
Correct |
194 ms |
26620 KB |
Output is correct |
53 |
Correct |
185 ms |
29512 KB |
Output is correct |
54 |
Correct |
187 ms |
34380 KB |
Output is correct |
55 |
Correct |
138 ms |
22176 KB |
Output is correct |
56 |
Correct |
140 ms |
23460 KB |
Output is correct |
57 |
Correct |
40 ms |
9808 KB |
Output is correct |
58 |
Correct |
143 ms |
26668 KB |
Output is correct |
59 |
Correct |
127 ms |
25960 KB |
Output is correct |
60 |
Correct |
170 ms |
33608 KB |
Output is correct |
61 |
Correct |
169 ms |
28488 KB |
Output is correct |
62 |
Correct |
25 ms |
8672 KB |
Output is correct |
63 |
Correct |
184 ms |
23368 KB |
Output is correct |