답안 #997419

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
997419 2024-06-12T09:36:07 Z crafticat Drawing (CEOI22_drawing) C++17
0 / 100
1500 ms 12320 KB
#include <bits/stdc++.h>

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

vector<vector<int>> g;
vector<bool> 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<point> points;
vector<int> ans;

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

void solve(int x, int par) {
    auto prev = m[par];
    for (auto child : g[x]) {
        if (par == child) continue;
        int maxAngle = inf;
        int sel = 0;
        for (int i = 0; i < points.size(); ++i) {
            auto p = points[i];
            if (vis[i]) continue;
            int ang = getAngle(prev,m[x],p);
            if (ang < maxAngle) {
                maxAngle = ang;
                sel = i;
            }
        }

        m[child] = points[sel];
        vis[sel] = true;
        ans[child] = sel;
        solve(child,x);
    }
}

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);
    vis.resize(n + 1);

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

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

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

    return 0;
}

Compilation message

Main.cpp: In function 'void solve(int, int)':
Main.cpp:38:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for (int i = 0; i < points.size(); ++i) {
      |                         ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1558 ms 12320 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1558 ms 12320 KB Time limit exceeded
2 Halted 0 ms 0 KB -