#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;
bool dead;
void read() {
cin >> x >> y;
}
bool operator < (const P& he) const {
return y < 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];
}
void dfs(int c, int p, vector<P>& pts, int l, int r) {
int use = -1;
for (int i = l; i <= r; i++) if (!pts[i].dead)
if (use == -1 || pts[i] < pts[use])
use = i;
assert(use != -1);
ans[pts[use].id] = c; pts[use].dead = 1;
int one = -1, two = -1;
for (int nxt : adj[c]) if (nxt != p) {
if (one == -1) one = nxt;
else two = nxt;
}
if (one == -1) return;
if (two == -1) {
dfs(one, c, pts, l, r);
} else {
int cnt = 0;
for (int m = l; m <= r; m++) if (!pts[m].dead) {
cnt++;
if (cnt == sub[one])
dfs(one, c, pts, l, m), dfs(two, c, pts, m + 1, r);
}
}
}
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, pts[i].dead = 0;
}
dfs(root, -1, pts, 0, n-1);
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();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
15408 KB |
Output is correct |
2 |
Execution timed out |
1572 ms |
17292 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5332 KB |
Output is correct |
2 |
Correct |
23 ms |
5476 KB |
Output is correct |
3 |
Correct |
22 ms |
5444 KB |
Output is correct |
4 |
Correct |
37 ms |
5572 KB |
Output is correct |
5 |
Correct |
31 ms |
5564 KB |
Output is correct |
6 |
Correct |
5 ms |
5332 KB |
Output is correct |
7 |
Correct |
17 ms |
5428 KB |
Output is correct |
8 |
Correct |
5 ms |
5296 KB |
Output is correct |
9 |
Correct |
22 ms |
5460 KB |
Output is correct |
10 |
Correct |
25 ms |
5476 KB |
Output is correct |
11 |
Correct |
37 ms |
5588 KB |
Output is correct |
12 |
Correct |
21 ms |
5472 KB |
Output is correct |
13 |
Correct |
5 ms |
5332 KB |
Output is correct |
14 |
Correct |
13 ms |
5332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5332 KB |
Output is correct |
2 |
Correct |
23 ms |
5476 KB |
Output is correct |
3 |
Correct |
22 ms |
5444 KB |
Output is correct |
4 |
Correct |
37 ms |
5572 KB |
Output is correct |
5 |
Correct |
31 ms |
5564 KB |
Output is correct |
6 |
Correct |
5 ms |
5332 KB |
Output is correct |
7 |
Correct |
17 ms |
5428 KB |
Output is correct |
8 |
Correct |
5 ms |
5296 KB |
Output is correct |
9 |
Correct |
22 ms |
5460 KB |
Output is correct |
10 |
Correct |
25 ms |
5476 KB |
Output is correct |
11 |
Correct |
37 ms |
5588 KB |
Output is correct |
12 |
Correct |
21 ms |
5472 KB |
Output is correct |
13 |
Correct |
5 ms |
5332 KB |
Output is correct |
14 |
Correct |
13 ms |
5332 KB |
Output is correct |
15 |
Correct |
11 ms |
5844 KB |
Output is correct |
16 |
Correct |
164 ms |
6264 KB |
Output is correct |
17 |
Correct |
113 ms |
6128 KB |
Output is correct |
18 |
Correct |
237 ms |
6436 KB |
Output is correct |
19 |
Correct |
252 ms |
6476 KB |
Output is correct |
20 |
Correct |
10 ms |
5844 KB |
Output is correct |
21 |
Correct |
93 ms |
6132 KB |
Output is correct |
22 |
Correct |
10 ms |
5844 KB |
Output is correct |
23 |
Correct |
101 ms |
6160 KB |
Output is correct |
24 |
Correct |
79 ms |
6056 KB |
Output is correct |
25 |
Correct |
243 ms |
6508 KB |
Output is correct |
26 |
Correct |
135 ms |
6256 KB |
Output is correct |
27 |
Correct |
10 ms |
5844 KB |
Output is correct |
28 |
Correct |
63 ms |
6068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5332 KB |
Output is correct |
2 |
Correct |
23 ms |
5476 KB |
Output is correct |
3 |
Correct |
22 ms |
5444 KB |
Output is correct |
4 |
Correct |
37 ms |
5572 KB |
Output is correct |
5 |
Correct |
31 ms |
5564 KB |
Output is correct |
6 |
Correct |
5 ms |
5332 KB |
Output is correct |
7 |
Correct |
17 ms |
5428 KB |
Output is correct |
8 |
Correct |
5 ms |
5296 KB |
Output is correct |
9 |
Correct |
22 ms |
5460 KB |
Output is correct |
10 |
Correct |
25 ms |
5476 KB |
Output is correct |
11 |
Correct |
37 ms |
5588 KB |
Output is correct |
12 |
Correct |
21 ms |
5472 KB |
Output is correct |
13 |
Correct |
5 ms |
5332 KB |
Output is correct |
14 |
Correct |
13 ms |
5332 KB |
Output is correct |
15 |
Correct |
11 ms |
5844 KB |
Output is correct |
16 |
Correct |
164 ms |
6264 KB |
Output is correct |
17 |
Correct |
113 ms |
6128 KB |
Output is correct |
18 |
Correct |
237 ms |
6436 KB |
Output is correct |
19 |
Correct |
252 ms |
6476 KB |
Output is correct |
20 |
Correct |
10 ms |
5844 KB |
Output is correct |
21 |
Correct |
93 ms |
6132 KB |
Output is correct |
22 |
Correct |
10 ms |
5844 KB |
Output is correct |
23 |
Correct |
101 ms |
6160 KB |
Output is correct |
24 |
Correct |
79 ms |
6056 KB |
Output is correct |
25 |
Correct |
243 ms |
6508 KB |
Output is correct |
26 |
Correct |
135 ms |
6256 KB |
Output is correct |
27 |
Correct |
10 ms |
5844 KB |
Output is correct |
28 |
Correct |
63 ms |
6068 KB |
Output is correct |
29 |
Correct |
74 ms |
12288 KB |
Output is correct |
30 |
Execution timed out |
1568 ms |
14500 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
15408 KB |
Output is correct |
2 |
Execution timed out |
1572 ms |
17292 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |