#include <bits/stdc++.h>
using namespace std;
#define sz(v) int(v.size())
#define ar array
typedef long long ll;
const int N = 2e5+10, MOD = 998244353;
struct P {
int x, y;
int id;
void read() {
cin >> x >> y;
}
bool operator < (const P& he) const {
return make_pair(x, y) < make_pair(he.x, he.y);
}
};
int n, sub[N], ans[N];
vector<int> adj[N];
int dfs_sub(int c, int p) {
sub[c] = 1;
for (int nxt : adj[c]) if (nxt != p)
sub[c] += dfs_sub(nxt, c);
return sub[c];
}
int get_sub(int c) {
return c == -1 ? 0 : sub[c];
}
void dfs(int c, int p, int l, int r, vector<P>& pts) {
int one = -1, two = -1;
for (int nxt : adj[c]) if (nxt != p) {
if (one == -1) one = nxt;
else two = nxt;
}
if (get_sub(one) > get_sub(two)) swap(one, two);
int m = l + get_sub(one);
ans[m] = c;
if (two == -1) return;
if (one == -1) {
dfs(two, c, m + 1, r, pts);
} else {
dfs(one, c, l, m - 1, pts);
dfs(two, c, m + 1, r, pts);
}
}
void solve() {
cin >> n;
for (int i = 0; i < n-1; i++) {
int a, b; cin >> a >> b, --a, --b;
adj[a].push_back(b), adj[b].push_back(a);
}
int root = -1;
for (int i = 0; i < n; i++) if (sz(adj[i]) == 1)
root = i;
dfs_sub(root, -1);
vector<P> pts(n);
for (int i = 0; i < n; i++) {
pts[i].read();
pts[i].id = i;
}
sort(pts.begin(), pts.end());
dfs(root, -1, 0, n-1, pts);
for (int i = 0; i < n; i++)
cout << ans[i]+1 << ' ';
cout << '\n';
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int T = 1;
// cin >> T;
while (T--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
11496 KB |
Output is correct |
2 |
Correct |
134 ms |
14332 KB |
Output is correct |
3 |
Correct |
103 ms |
14284 KB |
Output is correct |
4 |
Correct |
120 ms |
20084 KB |
Output is correct |
5 |
Correct |
109 ms |
16560 KB |
Output is correct |
6 |
Correct |
94 ms |
11624 KB |
Output is correct |
7 |
Correct |
127 ms |
12644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5204 KB |
Output is correct |
2 |
Correct |
6 ms |
5332 KB |
Output is correct |
3 |
Correct |
5 ms |
5332 KB |
Output is correct |
4 |
Correct |
5 ms |
5460 KB |
Output is correct |
5 |
Correct |
5 ms |
5460 KB |
Output is correct |
6 |
Correct |
5 ms |
5220 KB |
Output is correct |
7 |
Correct |
5 ms |
5332 KB |
Output is correct |
8 |
Correct |
7 ms |
5204 KB |
Output is correct |
9 |
Correct |
5 ms |
5332 KB |
Output is correct |
10 |
Correct |
5 ms |
5332 KB |
Output is correct |
11 |
Correct |
5 ms |
5460 KB |
Output is correct |
12 |
Correct |
5 ms |
5332 KB |
Output is correct |
13 |
Correct |
5 ms |
5204 KB |
Output is correct |
14 |
Correct |
6 ms |
5332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5204 KB |
Output is correct |
2 |
Correct |
6 ms |
5332 KB |
Output is correct |
3 |
Correct |
5 ms |
5332 KB |
Output is correct |
4 |
Correct |
5 ms |
5460 KB |
Output is correct |
5 |
Correct |
5 ms |
5460 KB |
Output is correct |
6 |
Correct |
5 ms |
5220 KB |
Output is correct |
7 |
Correct |
5 ms |
5332 KB |
Output is correct |
8 |
Correct |
7 ms |
5204 KB |
Output is correct |
9 |
Correct |
5 ms |
5332 KB |
Output is correct |
10 |
Correct |
5 ms |
5332 KB |
Output is correct |
11 |
Correct |
5 ms |
5460 KB |
Output is correct |
12 |
Correct |
5 ms |
5332 KB |
Output is correct |
13 |
Correct |
5 ms |
5204 KB |
Output is correct |
14 |
Correct |
6 ms |
5332 KB |
Output is correct |
15 |
Correct |
10 ms |
5588 KB |
Output is correct |
16 |
Correct |
12 ms |
5972 KB |
Output is correct |
17 |
Correct |
9 ms |
5844 KB |
Output is correct |
18 |
Correct |
9 ms |
6128 KB |
Output is correct |
19 |
Correct |
12 ms |
6096 KB |
Output is correct |
20 |
Correct |
9 ms |
5588 KB |
Output is correct |
21 |
Correct |
9 ms |
5856 KB |
Output is correct |
22 |
Correct |
9 ms |
5588 KB |
Output is correct |
23 |
Correct |
12 ms |
5868 KB |
Output is correct |
24 |
Correct |
10 ms |
5716 KB |
Output is correct |
25 |
Correct |
9 ms |
6100 KB |
Output is correct |
26 |
Correct |
9 ms |
6012 KB |
Output is correct |
27 |
Correct |
9 ms |
5504 KB |
Output is correct |
28 |
Correct |
9 ms |
5716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5204 KB |
Output is correct |
2 |
Correct |
6 ms |
5332 KB |
Output is correct |
3 |
Correct |
5 ms |
5332 KB |
Output is correct |
4 |
Correct |
5 ms |
5460 KB |
Output is correct |
5 |
Correct |
5 ms |
5460 KB |
Output is correct |
6 |
Correct |
5 ms |
5220 KB |
Output is correct |
7 |
Correct |
5 ms |
5332 KB |
Output is correct |
8 |
Correct |
7 ms |
5204 KB |
Output is correct |
9 |
Correct |
5 ms |
5332 KB |
Output is correct |
10 |
Correct |
5 ms |
5332 KB |
Output is correct |
11 |
Correct |
5 ms |
5460 KB |
Output is correct |
12 |
Correct |
5 ms |
5332 KB |
Output is correct |
13 |
Correct |
5 ms |
5204 KB |
Output is correct |
14 |
Correct |
6 ms |
5332 KB |
Output is correct |
15 |
Correct |
10 ms |
5588 KB |
Output is correct |
16 |
Correct |
12 ms |
5972 KB |
Output is correct |
17 |
Correct |
9 ms |
5844 KB |
Output is correct |
18 |
Correct |
9 ms |
6128 KB |
Output is correct |
19 |
Correct |
12 ms |
6096 KB |
Output is correct |
20 |
Correct |
9 ms |
5588 KB |
Output is correct |
21 |
Correct |
9 ms |
5856 KB |
Output is correct |
22 |
Correct |
9 ms |
5588 KB |
Output is correct |
23 |
Correct |
12 ms |
5868 KB |
Output is correct |
24 |
Correct |
10 ms |
5716 KB |
Output is correct |
25 |
Correct |
9 ms |
6100 KB |
Output is correct |
26 |
Correct |
9 ms |
6012 KB |
Output is correct |
27 |
Correct |
9 ms |
5504 KB |
Output is correct |
28 |
Correct |
9 ms |
5716 KB |
Output is correct |
29 |
Correct |
63 ms |
9544 KB |
Output is correct |
30 |
Correct |
65 ms |
12068 KB |
Output is correct |
31 |
Correct |
67 ms |
12004 KB |
Output is correct |
32 |
Correct |
77 ms |
14604 KB |
Output is correct |
33 |
Correct |
71 ms |
13872 KB |
Output is correct |
34 |
Correct |
65 ms |
9592 KB |
Output is correct |
35 |
Correct |
76 ms |
10456 KB |
Output is correct |
36 |
Correct |
55 ms |
9056 KB |
Output is correct |
37 |
Correct |
69 ms |
11728 KB |
Output is correct |
38 |
Correct |
87 ms |
11236 KB |
Output is correct |
39 |
Correct |
66 ms |
14612 KB |
Output is correct |
40 |
Correct |
79 ms |
13132 KB |
Output is correct |
41 |
Correct |
52 ms |
9020 KB |
Output is correct |
42 |
Correct |
66 ms |
10520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
11496 KB |
Output is correct |
2 |
Correct |
134 ms |
14332 KB |
Output is correct |
3 |
Correct |
103 ms |
14284 KB |
Output is correct |
4 |
Correct |
120 ms |
20084 KB |
Output is correct |
5 |
Correct |
109 ms |
16560 KB |
Output is correct |
6 |
Correct |
94 ms |
11624 KB |
Output is correct |
7 |
Correct |
127 ms |
12644 KB |
Output is correct |
8 |
Correct |
5 ms |
5204 KB |
Output is correct |
9 |
Correct |
6 ms |
5332 KB |
Output is correct |
10 |
Correct |
5 ms |
5332 KB |
Output is correct |
11 |
Correct |
5 ms |
5460 KB |
Output is correct |
12 |
Correct |
5 ms |
5460 KB |
Output is correct |
13 |
Correct |
5 ms |
5220 KB |
Output is correct |
14 |
Correct |
5 ms |
5332 KB |
Output is correct |
15 |
Correct |
7 ms |
5204 KB |
Output is correct |
16 |
Correct |
5 ms |
5332 KB |
Output is correct |
17 |
Correct |
5 ms |
5332 KB |
Output is correct |
18 |
Correct |
5 ms |
5460 KB |
Output is correct |
19 |
Correct |
5 ms |
5332 KB |
Output is correct |
20 |
Correct |
5 ms |
5204 KB |
Output is correct |
21 |
Correct |
6 ms |
5332 KB |
Output is correct |
22 |
Correct |
10 ms |
5588 KB |
Output is correct |
23 |
Correct |
12 ms |
5972 KB |
Output is correct |
24 |
Correct |
9 ms |
5844 KB |
Output is correct |
25 |
Correct |
9 ms |
6128 KB |
Output is correct |
26 |
Correct |
12 ms |
6096 KB |
Output is correct |
27 |
Correct |
9 ms |
5588 KB |
Output is correct |
28 |
Correct |
9 ms |
5856 KB |
Output is correct |
29 |
Correct |
9 ms |
5588 KB |
Output is correct |
30 |
Correct |
12 ms |
5868 KB |
Output is correct |
31 |
Correct |
10 ms |
5716 KB |
Output is correct |
32 |
Correct |
9 ms |
6100 KB |
Output is correct |
33 |
Correct |
9 ms |
6012 KB |
Output is correct |
34 |
Correct |
9 ms |
5504 KB |
Output is correct |
35 |
Correct |
9 ms |
5716 KB |
Output is correct |
36 |
Correct |
63 ms |
9544 KB |
Output is correct |
37 |
Correct |
65 ms |
12068 KB |
Output is correct |
38 |
Correct |
67 ms |
12004 KB |
Output is correct |
39 |
Correct |
77 ms |
14604 KB |
Output is correct |
40 |
Correct |
71 ms |
13872 KB |
Output is correct |
41 |
Correct |
65 ms |
9592 KB |
Output is correct |
42 |
Correct |
76 ms |
10456 KB |
Output is correct |
43 |
Correct |
55 ms |
9056 KB |
Output is correct |
44 |
Correct |
69 ms |
11728 KB |
Output is correct |
45 |
Correct |
87 ms |
11236 KB |
Output is correct |
46 |
Correct |
66 ms |
14612 KB |
Output is correct |
47 |
Correct |
79 ms |
13132 KB |
Output is correct |
48 |
Correct |
52 ms |
9020 KB |
Output is correct |
49 |
Correct |
66 ms |
10520 KB |
Output is correct |
50 |
Correct |
115 ms |
12308 KB |
Output is correct |
51 |
Correct |
223 ms |
22240 KB |
Output is correct |
52 |
Correct |
209 ms |
19728 KB |
Output is correct |
53 |
Correct |
247 ms |
29064 KB |
Output is correct |
54 |
Correct |
229 ms |
28648 KB |
Output is correct |
55 |
Correct |
224 ms |
16604 KB |
Output is correct |
56 |
Correct |
235 ms |
18520 KB |
Output is correct |
57 |
Correct |
32 ms |
7480 KB |
Output is correct |
58 |
Correct |
220 ms |
23088 KB |
Output is correct |
59 |
Correct |
235 ms |
21096 KB |
Output is correct |
60 |
Correct |
235 ms |
29016 KB |
Output is correct |
61 |
Correct |
243 ms |
25640 KB |
Output is correct |
62 |
Correct |
32 ms |
7488 KB |
Output is correct |
63 |
Correct |
225 ms |
18044 KB |
Output is correct |