/*The British Royal Family and a small cadre of English Fabian Socialists, in
conjunction with the Rockefellers and the Rothchilds, are engaged in a
conspiracy to greatly reduce the population of the human race in order to head
off a Malthusian catastrophe, a catastrophe that could easily be avoided by
simply building a massive amount of nuclear power plants and a number of massive
superhighways and bridges to connect all of the world's continents. But doing
that would cut into the conspiracy's profits. So the British Royal Family
invented environmentalism and neoliberalism in order to hide the truth. And in
order to further reduce the population, the British Royal Family is also the
world's foremost drug trafficking conspiracy. And it uses its control of the IMF
to push austerity in order to kill as many people in the global south as
possible.
And also Henry Kissinger is a gay KGB agent. */
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
int n, u, v, maxysegtree[800000], unusedsegtree[800000], subtreesize[200001], answer[200001];
pair<pair<int, int>, int> points[200000];
vector<vector<int>> graph;
int compy(int xa, int xb){
if (xa == -1 || xb == -1) return max(xa, xb);
if (points[xa].first.second > points[xb].first.second) return xa;
if (points[xa].first.second < points[xb].first.second) return xb;
if (points[xa] > points[xb]) return xa;
return xb;
}
int maxy(int l, int r, int node, int nodel, int noder){
if (noder <= l || r <= nodel) return -1;
if (l <= nodel && noder <= r) return maxysegtree[node];
int nodemid = (nodel + noder) / 2;
int a = maxy(l, r, 2 * node + 1, nodel, nodemid);
int b = maxy(l, r, 2 * node + 2, nodemid, noder);
return compy(a, b);
}
int countunused(int l, int r, int node, int nodel, int noder){
if (noder <= l || r <= nodel) return 0;
if (l <= nodel && noder <= r) return unusedsegtree[node];
int nodemid = (nodel + noder) / 2;
return countunused(l, r, 2 * node + 1, nodel, nodemid) + countunused(l, r, 2 * node + 2, nodemid, noder);
}
void build(int x, pair<pair<int, int>, int> val, int node, int nodel, int noder){
if (x < nodel || noder <= x) return;
if (x == nodel && x == noder - 1){
maxysegtree[node] = x;
unusedsegtree[node] = 1;
return;
}
int nodemid = (nodel + noder) / 2;
build(x, val, 2 * node + 1, nodel, nodemid);
build(x, val, 2 * node + 2, nodemid, noder);
unusedsegtree[node] = unusedsegtree[2 * node + 1] + unusedsegtree[2 * node + 2];
maxysegtree[node] = compy(maxysegtree[2 * node + 1], maxysegtree[2 * node + 2]);
}
void use(int x, int node, int nodel, int noder){
if (x < nodel || noder <= x) return;
if (x == nodel && x == noder - 1){
maxysegtree[node] = -1;
unusedsegtree[node] = 0;
return;
}
int nodemid = (nodel + noder) / 2;
use(x, 2 * node + 1, nodel, nodemid);
use(x, 2 * node + 2, nodemid, noder);
unusedsegtree[node] = unusedsegtree[2 * node + 1] + unusedsegtree[2 * node + 2];
maxysegtree[node] = compy(maxysegtree[2 * node + 1], maxysegtree[2 * node + 2]);
}
void stdfs(int node, int prev){
subtreesize[node] = 1;
for (int child: graph[node]){
if (child == prev) continue;
stdfs(child, node);
subtreesize[node] += subtreesize[child];
}
}
void compute(int rootnode, int prevnode, int pointl, int pointr){
int pointroot = maxy(pointl, pointr, 0, 0, n);
answer[points[pointroot].second + 1] = rootnode;
use(pointroot, 0, 0, n);
int cursor = pointl, minr, maxr, midr;
for (int child: graph[rootnode]){
if (child == prevnode) continue;
minr = cursor + 1;
maxr = pointr;
while (minr != maxr){
midr = (minr + maxr) / 2;
if (countunused(cursor, midr, 0, 0, n) < subtreesize[child]) minr = midr + 1;
else maxr = midr;
}
compute(child, rootnode, cursor, minr);
cursor = minr;
}
}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> n;
graph.resize(n + 1);
for (int i = 1; i < n; i++){
cin >> u >> v;
graph[u].push_back(v);
graph[v].push_back(u);
}
for (int i = 0; i < n; i++){
cin >> points[i].first.first >> points[i].first.second;
points[i].second = i;
}
sort(points, points + n);
for (int i = 0; i < n; i++) build(i, points[i], 0, 0, n);
stdfs(1, 0);
compute(1, 0, 0, n);
for (int i = 1; i <= n; i++) cout << answer[i] << ' ';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
166 ms |
19076 KB |
Output is correct |
2 |
Correct |
351 ms |
24620 KB |
Output is correct |
3 |
Correct |
354 ms |
22096 KB |
Output is correct |
4 |
Correct |
325 ms |
26964 KB |
Output is correct |
5 |
Correct |
385 ms |
26708 KB |
Output is correct |
6 |
Correct |
178 ms |
19352 KB |
Output is correct |
7 |
Correct |
298 ms |
20088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4956 KB |
Output is correct |
2 |
Correct |
8 ms |
4956 KB |
Output is correct |
3 |
Correct |
8 ms |
4952 KB |
Output is correct |
4 |
Correct |
9 ms |
5228 KB |
Output is correct |
5 |
Correct |
8 ms |
5212 KB |
Output is correct |
6 |
Correct |
5 ms |
4956 KB |
Output is correct |
7 |
Correct |
8 ms |
4956 KB |
Output is correct |
8 |
Correct |
5 ms |
4956 KB |
Output is correct |
9 |
Correct |
9 ms |
4944 KB |
Output is correct |
10 |
Correct |
8 ms |
4952 KB |
Output is correct |
11 |
Correct |
8 ms |
5116 KB |
Output is correct |
12 |
Correct |
10 ms |
4956 KB |
Output is correct |
13 |
Correct |
6 ms |
4952 KB |
Output is correct |
14 |
Correct |
7 ms |
4828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4956 KB |
Output is correct |
2 |
Correct |
8 ms |
4956 KB |
Output is correct |
3 |
Correct |
8 ms |
4952 KB |
Output is correct |
4 |
Correct |
9 ms |
5228 KB |
Output is correct |
5 |
Correct |
8 ms |
5212 KB |
Output is correct |
6 |
Correct |
5 ms |
4956 KB |
Output is correct |
7 |
Correct |
8 ms |
4956 KB |
Output is correct |
8 |
Correct |
5 ms |
4956 KB |
Output is correct |
9 |
Correct |
9 ms |
4944 KB |
Output is correct |
10 |
Correct |
8 ms |
4952 KB |
Output is correct |
11 |
Correct |
8 ms |
5116 KB |
Output is correct |
12 |
Correct |
10 ms |
4956 KB |
Output is correct |
13 |
Correct |
6 ms |
4952 KB |
Output is correct |
14 |
Correct |
7 ms |
4828 KB |
Output is correct |
15 |
Correct |
16 ms |
5468 KB |
Output is correct |
16 |
Correct |
25 ms |
5980 KB |
Output is correct |
17 |
Correct |
22 ms |
5724 KB |
Output is correct |
18 |
Correct |
24 ms |
6196 KB |
Output is correct |
19 |
Correct |
24 ms |
6232 KB |
Output is correct |
20 |
Correct |
13 ms |
5464 KB |
Output is correct |
21 |
Correct |
20 ms |
5724 KB |
Output is correct |
22 |
Correct |
14 ms |
5468 KB |
Output is correct |
23 |
Correct |
22 ms |
5876 KB |
Output is correct |
24 |
Correct |
22 ms |
5724 KB |
Output is correct |
25 |
Correct |
18 ms |
6228 KB |
Output is correct |
26 |
Correct |
23 ms |
5980 KB |
Output is correct |
27 |
Correct |
13 ms |
5524 KB |
Output is correct |
28 |
Correct |
19 ms |
5532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4956 KB |
Output is correct |
2 |
Correct |
8 ms |
4956 KB |
Output is correct |
3 |
Correct |
8 ms |
4952 KB |
Output is correct |
4 |
Correct |
9 ms |
5228 KB |
Output is correct |
5 |
Correct |
8 ms |
5212 KB |
Output is correct |
6 |
Correct |
5 ms |
4956 KB |
Output is correct |
7 |
Correct |
8 ms |
4956 KB |
Output is correct |
8 |
Correct |
5 ms |
4956 KB |
Output is correct |
9 |
Correct |
9 ms |
4944 KB |
Output is correct |
10 |
Correct |
8 ms |
4952 KB |
Output is correct |
11 |
Correct |
8 ms |
5116 KB |
Output is correct |
12 |
Correct |
10 ms |
4956 KB |
Output is correct |
13 |
Correct |
6 ms |
4952 KB |
Output is correct |
14 |
Correct |
7 ms |
4828 KB |
Output is correct |
15 |
Correct |
16 ms |
5468 KB |
Output is correct |
16 |
Correct |
25 ms |
5980 KB |
Output is correct |
17 |
Correct |
22 ms |
5724 KB |
Output is correct |
18 |
Correct |
24 ms |
6196 KB |
Output is correct |
19 |
Correct |
24 ms |
6232 KB |
Output is correct |
20 |
Correct |
13 ms |
5464 KB |
Output is correct |
21 |
Correct |
20 ms |
5724 KB |
Output is correct |
22 |
Correct |
14 ms |
5468 KB |
Output is correct |
23 |
Correct |
22 ms |
5876 KB |
Output is correct |
24 |
Correct |
22 ms |
5724 KB |
Output is correct |
25 |
Correct |
18 ms |
6228 KB |
Output is correct |
26 |
Correct |
23 ms |
5980 KB |
Output is correct |
27 |
Correct |
13 ms |
5524 KB |
Output is correct |
28 |
Correct |
19 ms |
5532 KB |
Output is correct |
29 |
Correct |
120 ms |
15952 KB |
Output is correct |
30 |
Correct |
247 ms |
20052 KB |
Output is correct |
31 |
Correct |
238 ms |
18512 KB |
Output is correct |
32 |
Correct |
188 ms |
21284 KB |
Output is correct |
33 |
Correct |
264 ms |
20304 KB |
Output is correct |
34 |
Correct |
121 ms |
15952 KB |
Output is correct |
35 |
Correct |
218 ms |
17140 KB |
Output is correct |
36 |
Correct |
108 ms |
15004 KB |
Output is correct |
37 |
Correct |
244 ms |
18768 KB |
Output is correct |
38 |
Correct |
273 ms |
18884 KB |
Output is correct |
39 |
Correct |
200 ms |
20308 KB |
Output is correct |
40 |
Correct |
289 ms |
18772 KB |
Output is correct |
41 |
Correct |
108 ms |
15184 KB |
Output is correct |
42 |
Correct |
219 ms |
16980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
166 ms |
19076 KB |
Output is correct |
2 |
Correct |
351 ms |
24620 KB |
Output is correct |
3 |
Correct |
354 ms |
22096 KB |
Output is correct |
4 |
Correct |
325 ms |
26964 KB |
Output is correct |
5 |
Correct |
385 ms |
26708 KB |
Output is correct |
6 |
Correct |
178 ms |
19352 KB |
Output is correct |
7 |
Correct |
298 ms |
20088 KB |
Output is correct |
8 |
Correct |
6 ms |
4956 KB |
Output is correct |
9 |
Correct |
8 ms |
4956 KB |
Output is correct |
10 |
Correct |
8 ms |
4952 KB |
Output is correct |
11 |
Correct |
9 ms |
5228 KB |
Output is correct |
12 |
Correct |
8 ms |
5212 KB |
Output is correct |
13 |
Correct |
5 ms |
4956 KB |
Output is correct |
14 |
Correct |
8 ms |
4956 KB |
Output is correct |
15 |
Correct |
5 ms |
4956 KB |
Output is correct |
16 |
Correct |
9 ms |
4944 KB |
Output is correct |
17 |
Correct |
8 ms |
4952 KB |
Output is correct |
18 |
Correct |
8 ms |
5116 KB |
Output is correct |
19 |
Correct |
10 ms |
4956 KB |
Output is correct |
20 |
Correct |
6 ms |
4952 KB |
Output is correct |
21 |
Correct |
7 ms |
4828 KB |
Output is correct |
22 |
Correct |
16 ms |
5468 KB |
Output is correct |
23 |
Correct |
25 ms |
5980 KB |
Output is correct |
24 |
Correct |
22 ms |
5724 KB |
Output is correct |
25 |
Correct |
24 ms |
6196 KB |
Output is correct |
26 |
Correct |
24 ms |
6232 KB |
Output is correct |
27 |
Correct |
13 ms |
5464 KB |
Output is correct |
28 |
Correct |
20 ms |
5724 KB |
Output is correct |
29 |
Correct |
14 ms |
5468 KB |
Output is correct |
30 |
Correct |
22 ms |
5876 KB |
Output is correct |
31 |
Correct |
22 ms |
5724 KB |
Output is correct |
32 |
Correct |
18 ms |
6228 KB |
Output is correct |
33 |
Correct |
23 ms |
5980 KB |
Output is correct |
34 |
Correct |
13 ms |
5524 KB |
Output is correct |
35 |
Correct |
19 ms |
5532 KB |
Output is correct |
36 |
Correct |
120 ms |
15952 KB |
Output is correct |
37 |
Correct |
247 ms |
20052 KB |
Output is correct |
38 |
Correct |
238 ms |
18512 KB |
Output is correct |
39 |
Correct |
188 ms |
21284 KB |
Output is correct |
40 |
Correct |
264 ms |
20304 KB |
Output is correct |
41 |
Correct |
121 ms |
15952 KB |
Output is correct |
42 |
Correct |
218 ms |
17140 KB |
Output is correct |
43 |
Correct |
108 ms |
15004 KB |
Output is correct |
44 |
Correct |
244 ms |
18768 KB |
Output is correct |
45 |
Correct |
273 ms |
18884 KB |
Output is correct |
46 |
Correct |
200 ms |
20308 KB |
Output is correct |
47 |
Correct |
289 ms |
18772 KB |
Output is correct |
48 |
Correct |
108 ms |
15184 KB |
Output is correct |
49 |
Correct |
219 ms |
16980 KB |
Output is correct |
50 |
Correct |
195 ms |
20168 KB |
Output is correct |
51 |
Correct |
790 ms |
37456 KB |
Output is correct |
52 |
Correct |
699 ms |
33904 KB |
Output is correct |
53 |
Correct |
751 ms |
37724 KB |
Output is correct |
54 |
Correct |
887 ms |
43612 KB |
Output is correct |
55 |
Correct |
336 ms |
28172 KB |
Output is correct |
56 |
Correct |
631 ms |
30040 KB |
Output is correct |
57 |
Correct |
60 ms |
12628 KB |
Output is correct |
58 |
Correct |
775 ms |
33864 KB |
Output is correct |
59 |
Correct |
690 ms |
33104 KB |
Output is correct |
60 |
Correct |
875 ms |
42544 KB |
Output is correct |
61 |
Correct |
847 ms |
36064 KB |
Output is correct |
62 |
Correct |
59 ms |
12500 KB |
Output is correct |
63 |
Correct |
626 ms |
29696 KB |
Output is correct |