답안 #862074

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
862074 2023-10-17T13:37:51 Z vgtcross Drawing (CEOI22_drawing) C++17
100 / 100
195 ms 52672 KB
#include <bits/stdc++.h>

#define X real()
#define Y imag()

using namespace std;

using ll = long long;
using P = complex<ll>;

const int N = 200200;

vector<int> adj[N];
vector<int> ord;
pair<P, int> pt[N];

bool cmp1(P a, P b) {
    if (a.X != b.X) return a.X < b.X;
    else return a.Y < b.Y;
}

bool cmp2(pair<P, int> a, pair<P, int> b) {
    return (conj(b.first - a.first) * (a.first - pt[0].first)).Y > 0;
}

void dfs(int u, int p) {
    vector<int> ch;
    for (int v : adj[u]) if (v != p) ch.push_back(v);
    if (ch.size() == 0) ord.push_back(u);
    else if (ch.size() == 1) {
        ord.push_back(u);
        dfs(ch[0], u);
    } else {
        dfs(ch[0], u);
        ord.push_back(u);
        dfs(ch[1], u);
    }
}

void solve() {
    int n;
    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);
    }
    
    int r = 1;
    while (adj[r].size() > 1) ++r;
    dfs(r, -1);
    
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        pt[i] = {{x, y}, i};
        if (cmp1(pt[i].first, pt[0].first)) swap(pt[i], pt[0]);
    }
    sort(pt+1, pt+n, cmp2);
    vector<int> ans(n);
    for (int i = 0; i < n; ++i) ans[pt[i].second] = ord[i];
    for (int i = 0; i < n; ++i) cout << ans[i] << " \n"[i == n-1];
}

int main() {
    cin.tie(0) -> sync_with_stdio(0);
    
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 18524 KB Output is correct
2 Correct 82 ms 27980 KB Output is correct
3 Correct 79 ms 25800 KB Output is correct
4 Correct 96 ms 36552 KB Output is correct
5 Correct 80 ms 27340 KB Output is correct
6 Correct 72 ms 18504 KB Output is correct
7 Correct 72 ms 20680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5980 KB Output is correct
2 Correct 4 ms 5980 KB Output is correct
3 Correct 4 ms 5980 KB Output is correct
4 Correct 4 ms 6492 KB Output is correct
5 Correct 4 ms 6236 KB Output is correct
6 Correct 4 ms 5980 KB Output is correct
7 Correct 5 ms 5980 KB Output is correct
8 Correct 4 ms 5980 KB Output is correct
9 Correct 4 ms 6236 KB Output is correct
10 Correct 4 ms 5980 KB Output is correct
11 Correct 4 ms 6492 KB Output is correct
12 Correct 3 ms 6236 KB Output is correct
13 Correct 3 ms 5980 KB Output is correct
14 Correct 4 ms 5980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5980 KB Output is correct
2 Correct 4 ms 5980 KB Output is correct
3 Correct 4 ms 5980 KB Output is correct
4 Correct 4 ms 6492 KB Output is correct
5 Correct 4 ms 6236 KB Output is correct
6 Correct 4 ms 5980 KB Output is correct
7 Correct 5 ms 5980 KB Output is correct
8 Correct 4 ms 5980 KB Output is correct
9 Correct 4 ms 6236 KB Output is correct
10 Correct 4 ms 5980 KB Output is correct
11 Correct 4 ms 6492 KB Output is correct
12 Correct 3 ms 6236 KB Output is correct
13 Correct 3 ms 5980 KB Output is correct
14 Correct 4 ms 5980 KB Output is correct
15 Correct 10 ms 8540 KB Output is correct
16 Correct 8 ms 9048 KB Output is correct
17 Correct 8 ms 8792 KB Output is correct
18 Correct 8 ms 9820 KB Output is correct
19 Correct 8 ms 9556 KB Output is correct
20 Correct 7 ms 8540 KB Output is correct
21 Correct 7 ms 8844 KB Output is correct
22 Correct 7 ms 8540 KB Output is correct
23 Correct 8 ms 8796 KB Output is correct
24 Correct 7 ms 8796 KB Output is correct
25 Correct 8 ms 9820 KB Output is correct
26 Correct 8 ms 9564 KB Output is correct
27 Correct 11 ms 8540 KB Output is correct
28 Correct 8 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5980 KB Output is correct
2 Correct 4 ms 5980 KB Output is correct
3 Correct 4 ms 5980 KB Output is correct
4 Correct 4 ms 6492 KB Output is correct
5 Correct 4 ms 6236 KB Output is correct
6 Correct 4 ms 5980 KB Output is correct
7 Correct 5 ms 5980 KB Output is correct
8 Correct 4 ms 5980 KB Output is correct
9 Correct 4 ms 6236 KB Output is correct
10 Correct 4 ms 5980 KB Output is correct
11 Correct 4 ms 6492 KB Output is correct
12 Correct 3 ms 6236 KB Output is correct
13 Correct 3 ms 5980 KB Output is correct
14 Correct 4 ms 5980 KB Output is correct
15 Correct 10 ms 8540 KB Output is correct
16 Correct 8 ms 9048 KB Output is correct
17 Correct 8 ms 8792 KB Output is correct
18 Correct 8 ms 9820 KB Output is correct
19 Correct 8 ms 9556 KB Output is correct
20 Correct 7 ms 8540 KB Output is correct
21 Correct 7 ms 8844 KB Output is correct
22 Correct 7 ms 8540 KB Output is correct
23 Correct 8 ms 8796 KB Output is correct
24 Correct 7 ms 8796 KB Output is correct
25 Correct 8 ms 9820 KB Output is correct
26 Correct 8 ms 9564 KB Output is correct
27 Correct 11 ms 8540 KB Output is correct
28 Correct 8 ms 8796 KB Output is correct
29 Correct 60 ms 13808 KB Output is correct
30 Correct 55 ms 20156 KB Output is correct
31 Correct 54 ms 17856 KB Output is correct
32 Correct 60 ms 24304 KB Output is correct
33 Correct 55 ms 22216 KB Output is correct
34 Correct 59 ms 13760 KB Output is correct
35 Correct 52 ms 16076 KB Output is correct
36 Correct 53 ms 13172 KB Output is correct
37 Correct 53 ms 18368 KB Output is correct
38 Correct 51 ms 18888 KB Output is correct
39 Correct 59 ms 24608 KB Output is correct
40 Correct 60 ms 24272 KB Output is correct
41 Correct 44 ms 13040 KB Output is correct
42 Correct 50 ms 15816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 18524 KB Output is correct
2 Correct 82 ms 27980 KB Output is correct
3 Correct 79 ms 25800 KB Output is correct
4 Correct 96 ms 36552 KB Output is correct
5 Correct 80 ms 27340 KB Output is correct
6 Correct 72 ms 18504 KB Output is correct
7 Correct 72 ms 20680 KB Output is correct
8 Correct 4 ms 5980 KB Output is correct
9 Correct 4 ms 5980 KB Output is correct
10 Correct 4 ms 5980 KB Output is correct
11 Correct 4 ms 6492 KB Output is correct
12 Correct 4 ms 6236 KB Output is correct
13 Correct 4 ms 5980 KB Output is correct
14 Correct 5 ms 5980 KB Output is correct
15 Correct 4 ms 5980 KB Output is correct
16 Correct 4 ms 6236 KB Output is correct
17 Correct 4 ms 5980 KB Output is correct
18 Correct 4 ms 6492 KB Output is correct
19 Correct 3 ms 6236 KB Output is correct
20 Correct 3 ms 5980 KB Output is correct
21 Correct 4 ms 5980 KB Output is correct
22 Correct 10 ms 8540 KB Output is correct
23 Correct 8 ms 9048 KB Output is correct
24 Correct 8 ms 8792 KB Output is correct
25 Correct 8 ms 9820 KB Output is correct
26 Correct 8 ms 9556 KB Output is correct
27 Correct 7 ms 8540 KB Output is correct
28 Correct 7 ms 8844 KB Output is correct
29 Correct 7 ms 8540 KB Output is correct
30 Correct 8 ms 8796 KB Output is correct
31 Correct 7 ms 8796 KB Output is correct
32 Correct 8 ms 9820 KB Output is correct
33 Correct 8 ms 9564 KB Output is correct
34 Correct 11 ms 8540 KB Output is correct
35 Correct 8 ms 8796 KB Output is correct
36 Correct 60 ms 13808 KB Output is correct
37 Correct 55 ms 20156 KB Output is correct
38 Correct 54 ms 17856 KB Output is correct
39 Correct 60 ms 24304 KB Output is correct
40 Correct 55 ms 22216 KB Output is correct
41 Correct 59 ms 13760 KB Output is correct
42 Correct 52 ms 16076 KB Output is correct
43 Correct 53 ms 13172 KB Output is correct
44 Correct 53 ms 18368 KB Output is correct
45 Correct 51 ms 18888 KB Output is correct
46 Correct 59 ms 24608 KB Output is correct
47 Correct 60 ms 24272 KB Output is correct
48 Correct 44 ms 13040 KB Output is correct
49 Correct 50 ms 15816 KB Output is correct
50 Correct 81 ms 19372 KB Output is correct
51 Correct 165 ms 34916 KB Output is correct
52 Correct 145 ms 32692 KB Output is correct
53 Correct 170 ms 52268 KB Output is correct
54 Correct 157 ms 44904 KB Output is correct
55 Correct 129 ms 25404 KB Output is correct
56 Correct 136 ms 28400 KB Output is correct
57 Correct 27 ms 10976 KB Output is correct
58 Correct 195 ms 34496 KB Output is correct
59 Correct 142 ms 32696 KB Output is correct
60 Correct 159 ms 52672 KB Output is correct
61 Correct 153 ms 39896 KB Output is correct
62 Correct 27 ms 10968 KB Output is correct
63 Correct 138 ms 28104 KB Output is correct