#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
#define pb push_back
#define ff first
#define ss second
const int MX = 2e5 + 5;
int n, x[MX], y[MX], sub[MX];
int ord[MX], ans[MX];
vector<int> adj[MX];
void dfs(int u, int pre) {
sub[u]++;
for(int i = 0; i < adj[u].size(); i++) {
if(adj[u][i] == pre) continue;
dfs(adj[u][i], u);
sub[u] += sub[adj[u][i]];
}
}
void solve(int u, int pre, int cnt) {
ans[ord[sub[u] + cnt - 1]] = u + 1;
for(int i = 0; i < adj[u].size(); i++) {
if(adj[u][i] == pre) continue;
solve(adj[u][i], u, cnt);
cnt += sub[adj[u][i]];
}
}
int main() {
ios::sync_with_stdio(0);cin.tie(0);
cin >> n;
for(int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
u--;v--;
adj[u].pb(v);
adj[v].pb(u);
}
for(int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
}
dfs(0, 0);
// if(n <= 10000) {
// go();
// return 0;
// }
vector<pair<double, int> > sl;
int mn = INT_MAX;
for(int i = 0; i < n; i++) {
if(mn <= x[i]) continue;
mn = x[i];
ord[0] = i;
}
for(int i = 0; i < n; i++) {
if(i == ord[0]) continue;
sl.pb({(double)(y[i] - y[ord[0]]) / (double)(x[i] - x[ord[0]]), i});
}
sort(sl.begin(), sl.end());
for(int i = 1; i < n; i++) {
ord[i] = sl[i - 1].ss;
}
solve(0, 0, 0);
for(int i = 0; i < n; i++) cout << ans[i] << " ";
}
Compilation message
Main.cpp: In function 'void dfs(int, int)':
Main.cpp:33:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(int i = 0; i < adj[u].size(); i++) {
| ~~^~~~~~~~~~~~~~~
Main.cpp: In function 'void solve(int, int, int)':
Main.cpp:42:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int i = 0; i < adj[u].size(); i++) {
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
16884 KB |
Output is correct |
2 |
Correct |
107 ms |
21168 KB |
Output is correct |
3 |
Correct |
81 ms |
19292 KB |
Output is correct |
4 |
Correct |
109 ms |
23328 KB |
Output is correct |
5 |
Correct |
115 ms |
22860 KB |
Output is correct |
6 |
Correct |
91 ms |
16808 KB |
Output is correct |
7 |
Correct |
98 ms |
17592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5428 KB |
Output is correct |
2 |
Correct |
5 ms |
5588 KB |
Output is correct |
3 |
Correct |
5 ms |
5548 KB |
Output is correct |
4 |
Correct |
5 ms |
5716 KB |
Output is correct |
5 |
Correct |
6 ms |
5660 KB |
Output is correct |
6 |
Correct |
5 ms |
5512 KB |
Output is correct |
7 |
Correct |
4 ms |
5552 KB |
Output is correct |
8 |
Correct |
5 ms |
5460 KB |
Output is correct |
9 |
Correct |
5 ms |
5588 KB |
Output is correct |
10 |
Correct |
4 ms |
5588 KB |
Output is correct |
11 |
Correct |
5 ms |
5704 KB |
Output is correct |
12 |
Correct |
4 ms |
5588 KB |
Output is correct |
13 |
Correct |
4 ms |
5452 KB |
Output is correct |
14 |
Correct |
5 ms |
5588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5428 KB |
Output is correct |
2 |
Correct |
5 ms |
5588 KB |
Output is correct |
3 |
Correct |
5 ms |
5548 KB |
Output is correct |
4 |
Correct |
5 ms |
5716 KB |
Output is correct |
5 |
Correct |
6 ms |
5660 KB |
Output is correct |
6 |
Correct |
5 ms |
5512 KB |
Output is correct |
7 |
Correct |
4 ms |
5552 KB |
Output is correct |
8 |
Correct |
5 ms |
5460 KB |
Output is correct |
9 |
Correct |
5 ms |
5588 KB |
Output is correct |
10 |
Correct |
4 ms |
5588 KB |
Output is correct |
11 |
Correct |
5 ms |
5704 KB |
Output is correct |
12 |
Correct |
4 ms |
5588 KB |
Output is correct |
13 |
Correct |
4 ms |
5452 KB |
Output is correct |
14 |
Correct |
5 ms |
5588 KB |
Output is correct |
15 |
Correct |
8 ms |
6164 KB |
Output is correct |
16 |
Correct |
8 ms |
6452 KB |
Output is correct |
17 |
Correct |
9 ms |
6320 KB |
Output is correct |
18 |
Correct |
11 ms |
6736 KB |
Output is correct |
19 |
Correct |
8 ms |
6612 KB |
Output is correct |
20 |
Correct |
8 ms |
6100 KB |
Output is correct |
21 |
Correct |
8 ms |
6272 KB |
Output is correct |
22 |
Correct |
8 ms |
6188 KB |
Output is correct |
23 |
Correct |
8 ms |
6356 KB |
Output is correct |
24 |
Correct |
11 ms |
6352 KB |
Output is correct |
25 |
Correct |
9 ms |
6732 KB |
Output is correct |
26 |
Correct |
8 ms |
6612 KB |
Output is correct |
27 |
Correct |
8 ms |
6100 KB |
Output is correct |
28 |
Correct |
11 ms |
6352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5428 KB |
Output is correct |
2 |
Correct |
5 ms |
5588 KB |
Output is correct |
3 |
Correct |
5 ms |
5548 KB |
Output is correct |
4 |
Correct |
5 ms |
5716 KB |
Output is correct |
5 |
Correct |
6 ms |
5660 KB |
Output is correct |
6 |
Correct |
5 ms |
5512 KB |
Output is correct |
7 |
Correct |
4 ms |
5552 KB |
Output is correct |
8 |
Correct |
5 ms |
5460 KB |
Output is correct |
9 |
Correct |
5 ms |
5588 KB |
Output is correct |
10 |
Correct |
4 ms |
5588 KB |
Output is correct |
11 |
Correct |
5 ms |
5704 KB |
Output is correct |
12 |
Correct |
4 ms |
5588 KB |
Output is correct |
13 |
Correct |
4 ms |
5452 KB |
Output is correct |
14 |
Correct |
5 ms |
5588 KB |
Output is correct |
15 |
Correct |
8 ms |
6164 KB |
Output is correct |
16 |
Correct |
8 ms |
6452 KB |
Output is correct |
17 |
Correct |
9 ms |
6320 KB |
Output is correct |
18 |
Correct |
11 ms |
6736 KB |
Output is correct |
19 |
Correct |
8 ms |
6612 KB |
Output is correct |
20 |
Correct |
8 ms |
6100 KB |
Output is correct |
21 |
Correct |
8 ms |
6272 KB |
Output is correct |
22 |
Correct |
8 ms |
6188 KB |
Output is correct |
23 |
Correct |
8 ms |
6356 KB |
Output is correct |
24 |
Correct |
11 ms |
6352 KB |
Output is correct |
25 |
Correct |
9 ms |
6732 KB |
Output is correct |
26 |
Correct |
8 ms |
6612 KB |
Output is correct |
27 |
Correct |
8 ms |
6100 KB |
Output is correct |
28 |
Correct |
11 ms |
6352 KB |
Output is correct |
29 |
Correct |
53 ms |
13344 KB |
Output is correct |
30 |
Correct |
60 ms |
16472 KB |
Output is correct |
31 |
Correct |
72 ms |
15388 KB |
Output is correct |
32 |
Correct |
72 ms |
17652 KB |
Output is correct |
33 |
Correct |
59 ms |
16912 KB |
Output is correct |
34 |
Correct |
50 ms |
13416 KB |
Output is correct |
35 |
Correct |
56 ms |
14128 KB |
Output is correct |
36 |
Correct |
47 ms |
12304 KB |
Output is correct |
37 |
Correct |
67 ms |
15496 KB |
Output is correct |
38 |
Correct |
57 ms |
15772 KB |
Output is correct |
39 |
Correct |
55 ms |
16884 KB |
Output is correct |
40 |
Correct |
60 ms |
15536 KB |
Output is correct |
41 |
Correct |
44 ms |
12332 KB |
Output is correct |
42 |
Correct |
50 ms |
14280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
16884 KB |
Output is correct |
2 |
Correct |
107 ms |
21168 KB |
Output is correct |
3 |
Correct |
81 ms |
19292 KB |
Output is correct |
4 |
Correct |
109 ms |
23328 KB |
Output is correct |
5 |
Correct |
115 ms |
22860 KB |
Output is correct |
6 |
Correct |
91 ms |
16808 KB |
Output is correct |
7 |
Correct |
98 ms |
17592 KB |
Output is correct |
8 |
Correct |
5 ms |
5428 KB |
Output is correct |
9 |
Correct |
5 ms |
5588 KB |
Output is correct |
10 |
Correct |
5 ms |
5548 KB |
Output is correct |
11 |
Correct |
5 ms |
5716 KB |
Output is correct |
12 |
Correct |
6 ms |
5660 KB |
Output is correct |
13 |
Correct |
5 ms |
5512 KB |
Output is correct |
14 |
Correct |
4 ms |
5552 KB |
Output is correct |
15 |
Correct |
5 ms |
5460 KB |
Output is correct |
16 |
Correct |
5 ms |
5588 KB |
Output is correct |
17 |
Correct |
4 ms |
5588 KB |
Output is correct |
18 |
Correct |
5 ms |
5704 KB |
Output is correct |
19 |
Correct |
4 ms |
5588 KB |
Output is correct |
20 |
Correct |
4 ms |
5452 KB |
Output is correct |
21 |
Correct |
5 ms |
5588 KB |
Output is correct |
22 |
Correct |
8 ms |
6164 KB |
Output is correct |
23 |
Correct |
8 ms |
6452 KB |
Output is correct |
24 |
Correct |
9 ms |
6320 KB |
Output is correct |
25 |
Correct |
11 ms |
6736 KB |
Output is correct |
26 |
Correct |
8 ms |
6612 KB |
Output is correct |
27 |
Correct |
8 ms |
6100 KB |
Output is correct |
28 |
Correct |
8 ms |
6272 KB |
Output is correct |
29 |
Correct |
8 ms |
6188 KB |
Output is correct |
30 |
Correct |
8 ms |
6356 KB |
Output is correct |
31 |
Correct |
11 ms |
6352 KB |
Output is correct |
32 |
Correct |
9 ms |
6732 KB |
Output is correct |
33 |
Correct |
8 ms |
6612 KB |
Output is correct |
34 |
Correct |
8 ms |
6100 KB |
Output is correct |
35 |
Correct |
11 ms |
6352 KB |
Output is correct |
36 |
Correct |
53 ms |
13344 KB |
Output is correct |
37 |
Correct |
60 ms |
16472 KB |
Output is correct |
38 |
Correct |
72 ms |
15388 KB |
Output is correct |
39 |
Correct |
72 ms |
17652 KB |
Output is correct |
40 |
Correct |
59 ms |
16912 KB |
Output is correct |
41 |
Correct |
50 ms |
13416 KB |
Output is correct |
42 |
Correct |
56 ms |
14128 KB |
Output is correct |
43 |
Correct |
47 ms |
12304 KB |
Output is correct |
44 |
Correct |
67 ms |
15496 KB |
Output is correct |
45 |
Correct |
57 ms |
15772 KB |
Output is correct |
46 |
Correct |
55 ms |
16884 KB |
Output is correct |
47 |
Correct |
60 ms |
15536 KB |
Output is correct |
48 |
Correct |
44 ms |
12332 KB |
Output is correct |
49 |
Correct |
50 ms |
14280 KB |
Output is correct |
50 |
Correct |
99 ms |
18172 KB |
Output is correct |
51 |
Correct |
268 ms |
33540 KB |
Output is correct |
52 |
Correct |
194 ms |
30720 KB |
Output is correct |
53 |
Correct |
222 ms |
33620 KB |
Output is correct |
54 |
Correct |
300 ms |
38468 KB |
Output is correct |
55 |
Correct |
215 ms |
26132 KB |
Output is correct |
56 |
Correct |
272 ms |
27448 KB |
Output is correct |
57 |
Correct |
29 ms |
9540 KB |
Output is correct |
58 |
Correct |
206 ms |
30516 KB |
Output is correct |
59 |
Correct |
224 ms |
29844 KB |
Output is correct |
60 |
Correct |
277 ms |
37636 KB |
Output is correct |
61 |
Correct |
226 ms |
32464 KB |
Output is correct |
62 |
Correct |
27 ms |
9524 KB |
Output is correct |
63 |
Correct |
238 ms |
27272 KB |
Output is correct |