// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 200005;
struct Point {
int x, y, i;
bool operator< (const Point &o) const {
if (x == o.x) return y < o.y;
return x < o.x;
}
Point& operator+= (const Point &o) {
x += o.x;
y += o.y;
return *this;
}
Point& operator-= (const Point &o) {
x -= o.x;
y -= o.y;
return *this;
}
ll cross(const Point& o) {
return (ll) x * o.y - (ll) y * o.x;
}
};
int n;
vi adj[MAXN];
Point pt[MAXN];
int ans[MAXN];
vi ch[MAXN];
int sub[MAXN];
void dfs(int u, int p) {
sub[u] = 1;
for (int v : adj[u]) {
if (v == p) {
continue;
}
ch[u].pb(v);
dfs(v, u);
sub[u] += sub[v];
}
}
void solve(int u, int l, int r) {
ans[pt[l].i] = u;
for (int v : ch[u]) {
solve(v, l + 1, l + sub[v]);
l += sub[v];
}
assert(l == r);
}
int main() {
#ifndef DEBUG
ios::sync_with_stdio(0), cin.tie(0);
#endif
cin >> n;
REP (i, 1, n) {
int u, v; cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
REP (i, 0, n) {
cin >> pt[i].x >> pt[i].y;
pt[i].i = i;
}
sort(pt, pt + n);
RREP (i, n - 1, 0) {
pt[i] -= pt[0];
}
sort(pt + 1, pt + n, [&] (Point &l, Point &r) {
return l.cross(r) > 0;
});
int rt = -1;
REP (i, 1, n + 1) {
if (SZ(adj[i]) <= 2) {
rt = i;
break;
}
}
assert(rt != -1);
dfs(rt, -1);
solve(rt, 0, n - 1);
REP (i, 0, n) {
cout << ans[i] << ' ';
}
cout << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
18600 KB |
Output is correct |
2 |
Correct |
139 ms |
25780 KB |
Output is correct |
3 |
Correct |
118 ms |
23372 KB |
Output is correct |
4 |
Correct |
139 ms |
28552 KB |
Output is correct |
5 |
Correct |
133 ms |
29296 KB |
Output is correct |
6 |
Correct |
109 ms |
18080 KB |
Output is correct |
7 |
Correct |
118 ms |
20988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9940 KB |
Output is correct |
2 |
Correct |
8 ms |
10196 KB |
Output is correct |
3 |
Correct |
10 ms |
10100 KB |
Output is correct |
4 |
Correct |
9 ms |
10376 KB |
Output is correct |
5 |
Correct |
9 ms |
10388 KB |
Output is correct |
6 |
Correct |
9 ms |
9940 KB |
Output is correct |
7 |
Correct |
8 ms |
10068 KB |
Output is correct |
8 |
Correct |
8 ms |
10008 KB |
Output is correct |
9 |
Correct |
8 ms |
10196 KB |
Output is correct |
10 |
Correct |
8 ms |
10068 KB |
Output is correct |
11 |
Correct |
10 ms |
10324 KB |
Output is correct |
12 |
Correct |
9 ms |
10196 KB |
Output is correct |
13 |
Correct |
8 ms |
9940 KB |
Output is correct |
14 |
Correct |
9 ms |
10196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9940 KB |
Output is correct |
2 |
Correct |
8 ms |
10196 KB |
Output is correct |
3 |
Correct |
10 ms |
10100 KB |
Output is correct |
4 |
Correct |
9 ms |
10376 KB |
Output is correct |
5 |
Correct |
9 ms |
10388 KB |
Output is correct |
6 |
Correct |
9 ms |
9940 KB |
Output is correct |
7 |
Correct |
8 ms |
10068 KB |
Output is correct |
8 |
Correct |
8 ms |
10008 KB |
Output is correct |
9 |
Correct |
8 ms |
10196 KB |
Output is correct |
10 |
Correct |
8 ms |
10068 KB |
Output is correct |
11 |
Correct |
10 ms |
10324 KB |
Output is correct |
12 |
Correct |
9 ms |
10196 KB |
Output is correct |
13 |
Correct |
8 ms |
9940 KB |
Output is correct |
14 |
Correct |
9 ms |
10196 KB |
Output is correct |
15 |
Correct |
13 ms |
10484 KB |
Output is correct |
16 |
Correct |
13 ms |
11092 KB |
Output is correct |
17 |
Correct |
13 ms |
10688 KB |
Output is correct |
18 |
Correct |
13 ms |
11480 KB |
Output is correct |
19 |
Correct |
13 ms |
11408 KB |
Output is correct |
20 |
Correct |
13 ms |
10416 KB |
Output is correct |
21 |
Correct |
13 ms |
10892 KB |
Output is correct |
22 |
Correct |
13 ms |
10452 KB |
Output is correct |
23 |
Correct |
14 ms |
10856 KB |
Output is correct |
24 |
Correct |
13 ms |
10736 KB |
Output is correct |
25 |
Correct |
13 ms |
11404 KB |
Output is correct |
26 |
Correct |
13 ms |
11276 KB |
Output is correct |
27 |
Correct |
13 ms |
10452 KB |
Output is correct |
28 |
Correct |
13 ms |
10748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9940 KB |
Output is correct |
2 |
Correct |
8 ms |
10196 KB |
Output is correct |
3 |
Correct |
10 ms |
10100 KB |
Output is correct |
4 |
Correct |
9 ms |
10376 KB |
Output is correct |
5 |
Correct |
9 ms |
10388 KB |
Output is correct |
6 |
Correct |
9 ms |
9940 KB |
Output is correct |
7 |
Correct |
8 ms |
10068 KB |
Output is correct |
8 |
Correct |
8 ms |
10008 KB |
Output is correct |
9 |
Correct |
8 ms |
10196 KB |
Output is correct |
10 |
Correct |
8 ms |
10068 KB |
Output is correct |
11 |
Correct |
10 ms |
10324 KB |
Output is correct |
12 |
Correct |
9 ms |
10196 KB |
Output is correct |
13 |
Correct |
8 ms |
9940 KB |
Output is correct |
14 |
Correct |
9 ms |
10196 KB |
Output is correct |
15 |
Correct |
13 ms |
10484 KB |
Output is correct |
16 |
Correct |
13 ms |
11092 KB |
Output is correct |
17 |
Correct |
13 ms |
10688 KB |
Output is correct |
18 |
Correct |
13 ms |
11480 KB |
Output is correct |
19 |
Correct |
13 ms |
11408 KB |
Output is correct |
20 |
Correct |
13 ms |
10416 KB |
Output is correct |
21 |
Correct |
13 ms |
10892 KB |
Output is correct |
22 |
Correct |
13 ms |
10452 KB |
Output is correct |
23 |
Correct |
14 ms |
10856 KB |
Output is correct |
24 |
Correct |
13 ms |
10736 KB |
Output is correct |
25 |
Correct |
13 ms |
11404 KB |
Output is correct |
26 |
Correct |
13 ms |
11276 KB |
Output is correct |
27 |
Correct |
13 ms |
10452 KB |
Output is correct |
28 |
Correct |
13 ms |
10748 KB |
Output is correct |
29 |
Correct |
83 ms |
16164 KB |
Output is correct |
30 |
Correct |
103 ms |
20872 KB |
Output is correct |
31 |
Correct |
87 ms |
18556 KB |
Output is correct |
32 |
Correct |
92 ms |
23656 KB |
Output is correct |
33 |
Correct |
87 ms |
22092 KB |
Output is correct |
34 |
Correct |
95 ms |
15628 KB |
Output is correct |
35 |
Correct |
87 ms |
18020 KB |
Output is correct |
36 |
Correct |
73 ms |
15052 KB |
Output is correct |
37 |
Correct |
86 ms |
19536 KB |
Output is correct |
38 |
Correct |
82 ms |
19280 KB |
Output is correct |
39 |
Correct |
91 ms |
22184 KB |
Output is correct |
40 |
Correct |
92 ms |
20684 KB |
Output is correct |
41 |
Correct |
71 ms |
14796 KB |
Output is correct |
42 |
Correct |
89 ms |
18124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
18600 KB |
Output is correct |
2 |
Correct |
139 ms |
25780 KB |
Output is correct |
3 |
Correct |
118 ms |
23372 KB |
Output is correct |
4 |
Correct |
139 ms |
28552 KB |
Output is correct |
5 |
Correct |
133 ms |
29296 KB |
Output is correct |
6 |
Correct |
109 ms |
18080 KB |
Output is correct |
7 |
Correct |
118 ms |
20988 KB |
Output is correct |
8 |
Correct |
9 ms |
9940 KB |
Output is correct |
9 |
Correct |
8 ms |
10196 KB |
Output is correct |
10 |
Correct |
10 ms |
10100 KB |
Output is correct |
11 |
Correct |
9 ms |
10376 KB |
Output is correct |
12 |
Correct |
9 ms |
10388 KB |
Output is correct |
13 |
Correct |
9 ms |
9940 KB |
Output is correct |
14 |
Correct |
8 ms |
10068 KB |
Output is correct |
15 |
Correct |
8 ms |
10008 KB |
Output is correct |
16 |
Correct |
8 ms |
10196 KB |
Output is correct |
17 |
Correct |
8 ms |
10068 KB |
Output is correct |
18 |
Correct |
10 ms |
10324 KB |
Output is correct |
19 |
Correct |
9 ms |
10196 KB |
Output is correct |
20 |
Correct |
8 ms |
9940 KB |
Output is correct |
21 |
Correct |
9 ms |
10196 KB |
Output is correct |
22 |
Correct |
13 ms |
10484 KB |
Output is correct |
23 |
Correct |
13 ms |
11092 KB |
Output is correct |
24 |
Correct |
13 ms |
10688 KB |
Output is correct |
25 |
Correct |
13 ms |
11480 KB |
Output is correct |
26 |
Correct |
13 ms |
11408 KB |
Output is correct |
27 |
Correct |
13 ms |
10416 KB |
Output is correct |
28 |
Correct |
13 ms |
10892 KB |
Output is correct |
29 |
Correct |
13 ms |
10452 KB |
Output is correct |
30 |
Correct |
14 ms |
10856 KB |
Output is correct |
31 |
Correct |
13 ms |
10736 KB |
Output is correct |
32 |
Correct |
13 ms |
11404 KB |
Output is correct |
33 |
Correct |
13 ms |
11276 KB |
Output is correct |
34 |
Correct |
13 ms |
10452 KB |
Output is correct |
35 |
Correct |
13 ms |
10748 KB |
Output is correct |
36 |
Correct |
83 ms |
16164 KB |
Output is correct |
37 |
Correct |
103 ms |
20872 KB |
Output is correct |
38 |
Correct |
87 ms |
18556 KB |
Output is correct |
39 |
Correct |
92 ms |
23656 KB |
Output is correct |
40 |
Correct |
87 ms |
22092 KB |
Output is correct |
41 |
Correct |
95 ms |
15628 KB |
Output is correct |
42 |
Correct |
87 ms |
18020 KB |
Output is correct |
43 |
Correct |
73 ms |
15052 KB |
Output is correct |
44 |
Correct |
86 ms |
19536 KB |
Output is correct |
45 |
Correct |
82 ms |
19280 KB |
Output is correct |
46 |
Correct |
91 ms |
22184 KB |
Output is correct |
47 |
Correct |
92 ms |
20684 KB |
Output is correct |
48 |
Correct |
71 ms |
14796 KB |
Output is correct |
49 |
Correct |
89 ms |
18124 KB |
Output is correct |
50 |
Correct |
134 ms |
19476 KB |
Output is correct |
51 |
Correct |
253 ms |
37520 KB |
Output is correct |
52 |
Correct |
304 ms |
30488 KB |
Output is correct |
53 |
Correct |
300 ms |
40016 KB |
Output is correct |
54 |
Correct |
279 ms |
46284 KB |
Output is correct |
55 |
Correct |
271 ms |
24980 KB |
Output is correct |
56 |
Correct |
268 ms |
30068 KB |
Output is correct |
57 |
Correct |
53 ms |
13244 KB |
Output is correct |
58 |
Correct |
320 ms |
33132 KB |
Output is correct |
59 |
Correct |
293 ms |
30612 KB |
Output is correct |
60 |
Correct |
296 ms |
45224 KB |
Output is correct |
61 |
Correct |
291 ms |
38544 KB |
Output is correct |
62 |
Correct |
55 ms |
13056 KB |
Output is correct |
63 |
Correct |
324 ms |
29836 KB |
Output is correct |