Submission #997527

# Submission time Handle Problem Language Result Execution time Memory
997527 2024-06-12T13:01:42 Z crafticat Drawing (CEOI22_drawing) C++17
100 / 100
175 ms 51648 KB
#include <bits/stdc++.h>

using namespace std;
using pii = pair<int,int>;

vector<vector<int>> g;
set<int> vis;
constexpr int inf = 1e9;
struct point {
    int x, y;

    point(int x, int y) : x(x), y(y) {}
    point() = default;
    point operator-(point other) {
        return {x - other.x,y - other.y};
    }
    int operator*(point other) {
        return x * other.y - y * other.x;
    }
};

vector<point> m;

vector<pair<point,int>> points;
vector<int> ans;

// 1 to 2, 2 to 3
int getAngle(point p1, point p2, point p3) {
    return (p3 - p1) * (p2 - p1);
}
//1
//5
//2
//6
//3
//4

void solve(int x, int par) {
    auto prev = m[par];
    for (auto child : g[x]) {
        if (par == child) continue;
        int sel = -1;
        int selId = -1;
        {
            auto i = *vis.begin();
            auto [p,id] = points[i];
            int ang = getAngle(m[x],p,points[sel == -1 ? 0 : sel].first);
            if (ang > 0 || sel == -1) {
                sel = i;
                selId = id;
            }
        }

        m[child] = points[sel].first;
        vis.erase(sel);
        ans[selId] = child;
        solve(child,x);
    }
}

point leftSide;

bool comp(pair<point,int> a, pair<point,int> b) {
    return getAngle(leftSide,a.first,b.first) > 0;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int n; cin >> n;

    g.resize(n + 1);
    for (int i = 0; i < n - 1; ++i) {
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    points.resize(n);

    int bestP = 0;
    for (int i = 0; i < n; ++i) {
        int x, y; cin >> x >> y;
        points[i] = {{x, y},i};
        if (points[bestP].first.x > x) {
            bestP = i;
        }
        if (points[bestP].first.x == x && points[bestP].first.y < y) {
            bestP = i;
        }
    }
    for (int i = 0; i < n; ++i) {
        vis.insert(i);
    }

    m.resize(n + 1);
    leftSide = points[bestP].first;
    sort(points.begin(),points.end(),comp);
    int j = 0;
    for (auto [p, i] : points) {
        if (points[bestP].first.x > p.x) {
            bestP =j;
        }
        if (points[bestP].first.x == p.x && points[bestP].first.y < p.x) {
            bestP = j;
        }
        j++;
    }

    m[0] = {0,0};
    m[1] = leftSide;
    vis.erase(bestP);
    ans.resize(n + 1);
    ans[points[bestP].second] = 1;

    solve(1,0);

    for (int i = 0; i < n; ++i) {
        cout << ans[i] << "\n";
    }

    return 0;
}

Compilation message

Main.cpp: In function 'void solve(int, int)':
Main.cpp:39:10: warning: variable 'prev' set but not used [-Wunused-but-set-variable]
   39 |     auto prev = m[par];
      |          ^~~~
# Verdict Execution time Memory Grader output
1 Correct 83 ms 15184 KB Output is correct
2 Correct 90 ms 25168 KB Output is correct
3 Correct 88 ms 22344 KB Output is correct
4 Correct 97 ms 28240 KB Output is correct
5 Correct 89 ms 27732 KB Output is correct
6 Correct 86 ms 18768 KB Output is correct
7 Correct 84 ms 19792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 860 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 3 ms 860 KB Output is correct
4 Correct 3 ms 1380 KB Output is correct
5 Correct 3 ms 1112 KB Output is correct
6 Correct 3 ms 744 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 3 ms 1116 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 3 ms 1116 KB Output is correct
12 Correct 3 ms 1116 KB Output is correct
13 Correct 4 ms 860 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 860 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 3 ms 860 KB Output is correct
4 Correct 3 ms 1380 KB Output is correct
5 Correct 3 ms 1112 KB Output is correct
6 Correct 3 ms 744 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 3 ms 1116 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 3 ms 1116 KB Output is correct
12 Correct 3 ms 1116 KB Output is correct
13 Correct 4 ms 860 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 6 ms 1640 KB Output is correct
16 Correct 7 ms 2140 KB Output is correct
17 Correct 7 ms 1884 KB Output is correct
18 Correct 7 ms 2652 KB Output is correct
19 Correct 7 ms 2520 KB Output is correct
20 Correct 6 ms 1628 KB Output is correct
21 Correct 6 ms 1884 KB Output is correct
22 Correct 7 ms 1628 KB Output is correct
23 Correct 7 ms 1880 KB Output is correct
24 Correct 6 ms 1996 KB Output is correct
25 Correct 8 ms 2396 KB Output is correct
26 Correct 6 ms 2660 KB Output is correct
27 Correct 6 ms 1628 KB Output is correct
28 Correct 7 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 860 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 3 ms 860 KB Output is correct
4 Correct 3 ms 1380 KB Output is correct
5 Correct 3 ms 1112 KB Output is correct
6 Correct 3 ms 744 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 3 ms 1116 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 3 ms 1116 KB Output is correct
12 Correct 3 ms 1116 KB Output is correct
13 Correct 4 ms 860 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 6 ms 1640 KB Output is correct
16 Correct 7 ms 2140 KB Output is correct
17 Correct 7 ms 1884 KB Output is correct
18 Correct 7 ms 2652 KB Output is correct
19 Correct 7 ms 2520 KB Output is correct
20 Correct 6 ms 1628 KB Output is correct
21 Correct 6 ms 1884 KB Output is correct
22 Correct 7 ms 1628 KB Output is correct
23 Correct 7 ms 1880 KB Output is correct
24 Correct 6 ms 1996 KB Output is correct
25 Correct 8 ms 2396 KB Output is correct
26 Correct 6 ms 2660 KB Output is correct
27 Correct 6 ms 1628 KB Output is correct
28 Correct 7 ms 1884 KB Output is correct
29 Correct 59 ms 10836 KB Output is correct
30 Correct 63 ms 18004 KB Output is correct
31 Correct 62 ms 16212 KB Output is correct
32 Correct 60 ms 19896 KB Output is correct
33 Correct 62 ms 18520 KB Output is correct
34 Correct 55 ms 13392 KB Output is correct
35 Correct 59 ms 14420 KB Output is correct
36 Correct 52 ms 11600 KB Output is correct
37 Correct 64 ms 16464 KB Output is correct
38 Correct 65 ms 16720 KB Output is correct
39 Correct 58 ms 18516 KB Output is correct
40 Correct 61 ms 16720 KB Output is correct
41 Correct 48 ms 11604 KB Output is correct
42 Correct 56 ms 14672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 15184 KB Output is correct
2 Correct 90 ms 25168 KB Output is correct
3 Correct 88 ms 22344 KB Output is correct
4 Correct 97 ms 28240 KB Output is correct
5 Correct 89 ms 27732 KB Output is correct
6 Correct 86 ms 18768 KB Output is correct
7 Correct 84 ms 19792 KB Output is correct
8 Correct 3 ms 860 KB Output is correct
9 Correct 2 ms 1116 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 3 ms 1380 KB Output is correct
12 Correct 3 ms 1112 KB Output is correct
13 Correct 3 ms 744 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 3 ms 860 KB Output is correct
18 Correct 3 ms 1116 KB Output is correct
19 Correct 3 ms 1116 KB Output is correct
20 Correct 4 ms 860 KB Output is correct
21 Correct 2 ms 860 KB Output is correct
22 Correct 6 ms 1640 KB Output is correct
23 Correct 7 ms 2140 KB Output is correct
24 Correct 7 ms 1884 KB Output is correct
25 Correct 7 ms 2652 KB Output is correct
26 Correct 7 ms 2520 KB Output is correct
27 Correct 6 ms 1628 KB Output is correct
28 Correct 6 ms 1884 KB Output is correct
29 Correct 7 ms 1628 KB Output is correct
30 Correct 7 ms 1880 KB Output is correct
31 Correct 6 ms 1996 KB Output is correct
32 Correct 8 ms 2396 KB Output is correct
33 Correct 6 ms 2660 KB Output is correct
34 Correct 6 ms 1628 KB Output is correct
35 Correct 7 ms 1884 KB Output is correct
36 Correct 59 ms 10836 KB Output is correct
37 Correct 63 ms 18004 KB Output is correct
38 Correct 62 ms 16212 KB Output is correct
39 Correct 60 ms 19896 KB Output is correct
40 Correct 62 ms 18520 KB Output is correct
41 Correct 55 ms 13392 KB Output is correct
42 Correct 59 ms 14420 KB Output is correct
43 Correct 52 ms 11600 KB Output is correct
44 Correct 64 ms 16464 KB Output is correct
45 Correct 65 ms 16720 KB Output is correct
46 Correct 58 ms 18516 KB Output is correct
47 Correct 61 ms 16720 KB Output is correct
48 Correct 48 ms 11604 KB Output is correct
49 Correct 56 ms 14672 KB Output is correct
50 Correct 96 ms 20820 KB Output is correct
51 Correct 169 ms 44412 KB Output is correct
52 Correct 163 ms 40020 KB Output is correct
53 Correct 159 ms 44624 KB Output is correct
54 Correct 175 ms 51648 KB Output is correct
55 Correct 152 ms 32988 KB Output is correct
56 Correct 172 ms 35156 KB Output is correct
57 Correct 30 ms 7252 KB Output is correct
58 Correct 164 ms 39760 KB Output is correct
59 Correct 170 ms 38772 KB Output is correct
60 Correct 159 ms 50260 KB Output is correct
61 Correct 167 ms 42832 KB Output is correct
62 Correct 29 ms 7260 KB Output is correct
63 Correct 161 ms 34896 KB Output is correct