# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1099365 |
2024-10-11T08:45:42 Z |
Zero_OP |
Drawing (CEOI22_drawing) |
C++14 |
|
150 ms |
38596 KB |
#include <bits/stdc++.h>
using namespace std;
#define all(v) begin(v), end(v)
#define compact(v) v.erase(unique(all(v)), end(v))
#define sz(v) (int)v.size()
#define dbg(x) "[" #x " = " << (x) << "]"
using ll = long long;
using ld = long double;
template<typename T>
bool minimize(T& a, const T& b){
if(a > b) return a = b, true; return false;
}
template<typename T>
bool maximize(T& a, const T& b){
if(a < b) return a = b, true; return false;
}
struct point{
int x, y;
point(int x = 0, int y = 0) : x(x), y(y) {}
friend istream& operator >> (istream& in, point& p){ return in >> p.x >> p.y; }
};
ll cross(const point& a, const point& b, const point& c){
ll x1 = b.x - a.x, x2 = c.x - a.x;
ll y1 = b.y - a.y, y2 = c.y - a.y;
return x1 * y2 - x2 * y1;
}
bool ccw(const point& a, const point& b, const point& c){
return cross(a, b, c) > 0;
}
const int MAX = 2e5 + 5;
int n, answer[MAX], ptr;
point points[MAX];
vector<int> adj[MAX], on;
int sz[MAX];
int predfs(int u){
sz[u] = 1;
for(int v : adj[u]){
adj[v].erase(find(all(adj[v]), u));
sz[u] += predfs(v);
}
return sz[u];
}
int select_root(){
for(int i = 1; i <= n; ++i){
if(sz(adj[i]) < 3){
return i;
}
}
assert(false);
}
int select_point(){
int best = 1;
for(int i = 2; i <= n; ++i){
if(points[best].x > points[i].x || (points[best].x == points[i].x && points[best].y > points[i].y)){
best = i;
}
}
return best;
}
int root_of_points;
bool comparator(int u, int v){
return ccw(points[root_of_points], points[u], points[v]);
}
void dfs(int u){
// cout << u << '\n';
for(int v : adj[u]){
answer[on[ptr++]] = v;
dfs(v);
}
}
void solve(int u, int last_id, vector<int>& id_points){
if(sz(adj[u]) == 0) return;
root_of_points = last_id;
sort(all(id_points), comparator);
if(sz(adj[u]) == 1){
int v = adj[u][0], nxt = id_points.back();
answer[nxt] = v;
id_points.pop_back();
solve(v, nxt, id_points);
} else{
int v1 = adj[u][1];
int v2 = adj[u][0];
vector<int> left_id_points, right_id_points;
for(int i = 0; i < sz[v1]; ++i){
left_id_points.push_back(id_points[i]);
}
for(int i = sz[v1]; i < sz[u] - 1; ++i){
right_id_points.push_back(id_points[i]);
}
int nxt1 = left_id_points.back();
int nxt2 = right_id_points.back();
answer[nxt1] = v1;
answer[nxt2] = v2;
left_id_points.pop_back();
right_id_points.pop_back();
solve(v1, nxt1, left_id_points);
solve(v2, nxt2, right_id_points);
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#define filename "task"
if(fopen(filename".inp", "r")){
freopen(filename".inp", "r", stdin);
freopen(filename".out", "w", stdout);
}
cin >> n;
for(int i = 1; i < n; ++i){
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i = 1; i <= n; ++i){
cin >> points[i];
}
int r = select_root();
int id = select_point();
for(int i = 1; i <= n; ++i){
if(i != id) on.push_back(i);
}
predfs(r);
root_of_points = r;
sort(all(on), comparator);
answer[id] = r;
ptr = 0;
dfs(r);
for(int i = 1; i <= n; ++i){
cout << answer[i] << ' ';
}
return 0;
}
Compilation message
Main.cpp: In function 'bool minimize(T&, const T&)':
Main.cpp:15:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
15 | if(a > b) return a = b, true; return false;
| ^~
Main.cpp:15:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
15 | if(a > b) return a = b, true; return false;
| ^~~~~~
Main.cpp: In function 'bool maximize(T&, const T&)':
Main.cpp:20:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
20 | if(a < b) return a = b, true; return false;
| ^~
Main.cpp:20:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
20 | if(a < b) return a = b, true; return false;
| ^~~~~~
Main.cpp: In function 'int main()':
Main.cpp:132:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
132 | freopen(filename".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:133:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
133 | freopen(filename".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
15828 KB |
Output is correct |
2 |
Correct |
74 ms |
21364 KB |
Output is correct |
3 |
Correct |
71 ms |
20164 KB |
Output is correct |
4 |
Correct |
89 ms |
23240 KB |
Output is correct |
5 |
Correct |
73 ms |
23792 KB |
Output is correct |
6 |
Correct |
65 ms |
15816 KB |
Output is correct |
7 |
Correct |
80 ms |
16592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7004 KB |
Output is correct |
2 |
Correct |
6 ms |
7004 KB |
Output is correct |
3 |
Correct |
5 ms |
7004 KB |
Output is correct |
4 |
Correct |
6 ms |
7260 KB |
Output is correct |
5 |
Correct |
5 ms |
7260 KB |
Output is correct |
6 |
Correct |
5 ms |
7004 KB |
Output is correct |
7 |
Correct |
4 ms |
7004 KB |
Output is correct |
8 |
Correct |
4 ms |
6996 KB |
Output is correct |
9 |
Correct |
5 ms |
7260 KB |
Output is correct |
10 |
Correct |
4 ms |
6920 KB |
Output is correct |
11 |
Correct |
5 ms |
7256 KB |
Output is correct |
12 |
Correct |
5 ms |
7032 KB |
Output is correct |
13 |
Correct |
5 ms |
7004 KB |
Output is correct |
14 |
Correct |
5 ms |
7004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7004 KB |
Output is correct |
2 |
Correct |
6 ms |
7004 KB |
Output is correct |
3 |
Correct |
5 ms |
7004 KB |
Output is correct |
4 |
Correct |
6 ms |
7260 KB |
Output is correct |
5 |
Correct |
5 ms |
7260 KB |
Output is correct |
6 |
Correct |
5 ms |
7004 KB |
Output is correct |
7 |
Correct |
4 ms |
7004 KB |
Output is correct |
8 |
Correct |
4 ms |
6996 KB |
Output is correct |
9 |
Correct |
5 ms |
7260 KB |
Output is correct |
10 |
Correct |
4 ms |
6920 KB |
Output is correct |
11 |
Correct |
5 ms |
7256 KB |
Output is correct |
12 |
Correct |
5 ms |
7032 KB |
Output is correct |
13 |
Correct |
5 ms |
7004 KB |
Output is correct |
14 |
Correct |
5 ms |
7004 KB |
Output is correct |
15 |
Correct |
8 ms |
7512 KB |
Output is correct |
16 |
Correct |
8 ms |
8024 KB |
Output is correct |
17 |
Correct |
8 ms |
7768 KB |
Output is correct |
18 |
Correct |
8 ms |
8028 KB |
Output is correct |
19 |
Correct |
9 ms |
8028 KB |
Output is correct |
20 |
Correct |
8 ms |
7516 KB |
Output is correct |
21 |
Correct |
8 ms |
7772 KB |
Output is correct |
22 |
Correct |
8 ms |
7516 KB |
Output is correct |
23 |
Correct |
8 ms |
7772 KB |
Output is correct |
24 |
Correct |
9 ms |
7768 KB |
Output is correct |
25 |
Correct |
9 ms |
8028 KB |
Output is correct |
26 |
Correct |
9 ms |
8028 KB |
Output is correct |
27 |
Correct |
9 ms |
7488 KB |
Output is correct |
28 |
Correct |
8 ms |
7772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7004 KB |
Output is correct |
2 |
Correct |
6 ms |
7004 KB |
Output is correct |
3 |
Correct |
5 ms |
7004 KB |
Output is correct |
4 |
Correct |
6 ms |
7260 KB |
Output is correct |
5 |
Correct |
5 ms |
7260 KB |
Output is correct |
6 |
Correct |
5 ms |
7004 KB |
Output is correct |
7 |
Correct |
4 ms |
7004 KB |
Output is correct |
8 |
Correct |
4 ms |
6996 KB |
Output is correct |
9 |
Correct |
5 ms |
7260 KB |
Output is correct |
10 |
Correct |
4 ms |
6920 KB |
Output is correct |
11 |
Correct |
5 ms |
7256 KB |
Output is correct |
12 |
Correct |
5 ms |
7032 KB |
Output is correct |
13 |
Correct |
5 ms |
7004 KB |
Output is correct |
14 |
Correct |
5 ms |
7004 KB |
Output is correct |
15 |
Correct |
8 ms |
7512 KB |
Output is correct |
16 |
Correct |
8 ms |
8024 KB |
Output is correct |
17 |
Correct |
8 ms |
7768 KB |
Output is correct |
18 |
Correct |
8 ms |
8028 KB |
Output is correct |
19 |
Correct |
9 ms |
8028 KB |
Output is correct |
20 |
Correct |
8 ms |
7516 KB |
Output is correct |
21 |
Correct |
8 ms |
7772 KB |
Output is correct |
22 |
Correct |
8 ms |
7516 KB |
Output is correct |
23 |
Correct |
8 ms |
7772 KB |
Output is correct |
24 |
Correct |
9 ms |
7768 KB |
Output is correct |
25 |
Correct |
9 ms |
8028 KB |
Output is correct |
26 |
Correct |
9 ms |
8028 KB |
Output is correct |
27 |
Correct |
9 ms |
7488 KB |
Output is correct |
28 |
Correct |
8 ms |
7772 KB |
Output is correct |
29 |
Correct |
54 ms |
13012 KB |
Output is correct |
30 |
Correct |
59 ms |
17104 KB |
Output is correct |
31 |
Correct |
54 ms |
15492 KB |
Output is correct |
32 |
Correct |
57 ms |
18388 KB |
Output is correct |
33 |
Correct |
55 ms |
17616 KB |
Output is correct |
34 |
Correct |
46 ms |
13016 KB |
Output is correct |
35 |
Correct |
52 ms |
14036 KB |
Output is correct |
36 |
Correct |
41 ms |
12236 KB |
Output is correct |
37 |
Correct |
54 ms |
15916 KB |
Output is correct |
38 |
Correct |
51 ms |
16172 KB |
Output is correct |
39 |
Correct |
57 ms |
17360 KB |
Output is correct |
40 |
Correct |
50 ms |
16080 KB |
Output is correct |
41 |
Correct |
42 ms |
12236 KB |
Output is correct |
42 |
Correct |
49 ms |
14292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
15828 KB |
Output is correct |
2 |
Correct |
74 ms |
21364 KB |
Output is correct |
3 |
Correct |
71 ms |
20164 KB |
Output is correct |
4 |
Correct |
89 ms |
23240 KB |
Output is correct |
5 |
Correct |
73 ms |
23792 KB |
Output is correct |
6 |
Correct |
65 ms |
15816 KB |
Output is correct |
7 |
Correct |
80 ms |
16592 KB |
Output is correct |
8 |
Correct |
5 ms |
7004 KB |
Output is correct |
9 |
Correct |
6 ms |
7004 KB |
Output is correct |
10 |
Correct |
5 ms |
7004 KB |
Output is correct |
11 |
Correct |
6 ms |
7260 KB |
Output is correct |
12 |
Correct |
5 ms |
7260 KB |
Output is correct |
13 |
Correct |
5 ms |
7004 KB |
Output is correct |
14 |
Correct |
4 ms |
7004 KB |
Output is correct |
15 |
Correct |
4 ms |
6996 KB |
Output is correct |
16 |
Correct |
5 ms |
7260 KB |
Output is correct |
17 |
Correct |
4 ms |
6920 KB |
Output is correct |
18 |
Correct |
5 ms |
7256 KB |
Output is correct |
19 |
Correct |
5 ms |
7032 KB |
Output is correct |
20 |
Correct |
5 ms |
7004 KB |
Output is correct |
21 |
Correct |
5 ms |
7004 KB |
Output is correct |
22 |
Correct |
8 ms |
7512 KB |
Output is correct |
23 |
Correct |
8 ms |
8024 KB |
Output is correct |
24 |
Correct |
8 ms |
7768 KB |
Output is correct |
25 |
Correct |
8 ms |
8028 KB |
Output is correct |
26 |
Correct |
9 ms |
8028 KB |
Output is correct |
27 |
Correct |
8 ms |
7516 KB |
Output is correct |
28 |
Correct |
8 ms |
7772 KB |
Output is correct |
29 |
Correct |
8 ms |
7516 KB |
Output is correct |
30 |
Correct |
8 ms |
7772 KB |
Output is correct |
31 |
Correct |
9 ms |
7768 KB |
Output is correct |
32 |
Correct |
9 ms |
8028 KB |
Output is correct |
33 |
Correct |
9 ms |
8028 KB |
Output is correct |
34 |
Correct |
9 ms |
7488 KB |
Output is correct |
35 |
Correct |
8 ms |
7772 KB |
Output is correct |
36 |
Correct |
54 ms |
13012 KB |
Output is correct |
37 |
Correct |
59 ms |
17104 KB |
Output is correct |
38 |
Correct |
54 ms |
15492 KB |
Output is correct |
39 |
Correct |
57 ms |
18388 KB |
Output is correct |
40 |
Correct |
55 ms |
17616 KB |
Output is correct |
41 |
Correct |
46 ms |
13016 KB |
Output is correct |
42 |
Correct |
52 ms |
14036 KB |
Output is correct |
43 |
Correct |
41 ms |
12236 KB |
Output is correct |
44 |
Correct |
54 ms |
15916 KB |
Output is correct |
45 |
Correct |
51 ms |
16172 KB |
Output is correct |
46 |
Correct |
57 ms |
17360 KB |
Output is correct |
47 |
Correct |
50 ms |
16080 KB |
Output is correct |
48 |
Correct |
42 ms |
12236 KB |
Output is correct |
49 |
Correct |
49 ms |
14292 KB |
Output is correct |
50 |
Correct |
78 ms |
16840 KB |
Output is correct |
51 |
Correct |
143 ms |
32456 KB |
Output is correct |
52 |
Correct |
134 ms |
27844 KB |
Output is correct |
53 |
Correct |
148 ms |
32448 KB |
Output is correct |
54 |
Correct |
147 ms |
38596 KB |
Output is correct |
55 |
Correct |
134 ms |
22980 KB |
Output is correct |
56 |
Correct |
142 ms |
24772 KB |
Output is correct |
57 |
Correct |
25 ms |
10124 KB |
Output is correct |
58 |
Correct |
139 ms |
28612 KB |
Output is correct |
59 |
Correct |
130 ms |
27848 KB |
Output is correct |
60 |
Correct |
147 ms |
37312 KB |
Output is correct |
61 |
Correct |
150 ms |
31256 KB |
Output is correct |
62 |
Correct |
25 ms |
10196 KB |
Output is correct |
63 |
Correct |
141 ms |
24520 KB |
Output is correct |