104252024-04-02 10:22:03szilÚthálózatbővítéscpp17Wrong answer 0/100442ms63848 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

struct Point {
    ll x, y;
};

struct Line {
    int u, v;
};

ll cross(Point p, Point q) {
    return p.x * q.y - p.y * q.x;
}

ll squared(Point p) {
    return p.x*p.x+p.y*p.y;
}

ll forog(Point a, Point b, Point c) {
    b.x -= a.x; c.x -= a.x;
    b.y -= a.y; c.y -= a.y;
    ll o = cross(b, c);
    if (o > 0) return 1;
    if (o == 0) return 0;
    if (o < 0) return -1;
}

bool operator<(const Point &p, const Point &q) {
    if ((p.x >= 0) == (q.x >= 0)) {
        ll o = cross(p, q);
        if (o == 0) return squared(p) < squared(q);
        return cross(p, q) > 0;
    }
    return (p.x >= 0) < (q.x >= 0);
}

const int MAXN = 200'001;

Point points[MAXN];
Line lines[MAXN];
bool ans[MAXN];
vector<Line> to_remove[MAXN], to_add[MAXN];
set<Line> s;
int n, ox, oy;

bool operator<(const Line &a, const Line &b) {
    Point p1 = points[a.u], q1 = points[a.v], p2 = points[b.u], q2 = points[b.v];
    if (cross(p1, q1) < 0) swap(p1, q1);
    return forog(p1, q1, p2) < 0 || forog(p1, q1, q2) < 0;
}

void solve() {
    vector<int> indices(n);
    iota(indices.begin(), indices.end(), 1);
    sort(indices.begin(), indices.end(), [&](int i, int j){
        return points[i] < points[j];
    });
    for (int i = 0; i < n; ) {
        int j = i;
        while (j + 1 < n && cross(points[indices[i]], points[indices[j + 1]]) == 0) j++;
        /*cerr << "start: ";
        for (int k = i; k <= j; k++) {
            cerr << indices[k] << " ";
        }
        cerr << endl;
        for (Line l : s) cerr << l.u << "-" << l.v << "; ";
        cerr << endl;*/
        for (int k = i; k <= j; k++) {
            for (Line l : to_remove[indices[k]]) {
                // cerr << "rem " << l.u << " " << l.v << endl;
                s.erase(l);
            }
        }
        if (s.lower_bound({indices[i], indices[i]}) == s.begin()) {
            ans[indices[i]] = true;
        }
        for (int k = i; k <= j; k++) {
            for (Line l : to_add[indices[k]]) {
                // cerr << "add " << l.u << " " << l.v << endl;
                s.insert(l);
            }
        }
        i = j + 1;
    }    
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> ox >> oy;
    for (int i = 1; i <= n; i++) {
        cin >> points[i].x >> points[i].y;
        points[i].x -= ox;
        points[i].y -= oy;
    }
    for (int i = 0; i < n-1; i++) {
        int &u = lines[i].u, &v = lines[i].v;
        cin >> u >> v;
        if (points[v] < points[u]) swap(u, v);

        ll o = cross(points[u], points[v]);
        if (o > 0) {
            to_add[u].emplace_back(lines[i]);
            to_remove[v].emplace_back(lines[i]);
        } else if (o < 0) {
            // cerr << "pre " << u << " " << v << endl;
            s.insert(lines[i]);
            to_remove[u].emplace_back(lines[i]);
            to_add[v].emplace_back(lines[i]);
        }
    }
    solve();
    cout << count(ans+1, ans+n+1, true) << "\n";
    for (int i = 1; i <= n; i++) {
        if (ans[i]) cout << i << " ";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted9ms20692 KiB
2Wrong answer120ms33308 KiB
subtask20/10
3Wrong answer8ms22888 KiB
4Accepted8ms23168 KiB
5Accepted8ms23080 KiB
6Wrong answer9ms23368 KiB
7Wrong answer12ms23728 KiB
subtask30/20
8Accepted10ms23888 KiB
9Wrong answer9ms24112 KiB
10Wrong answer12ms24208 KiB
11Wrong answer18ms24936 KiB
12Wrong answer28ms25956 KiB
13Wrong answer115ms33392 KiB
14Wrong answer239ms44376 KiB
15Accepted19ms29812 KiB
16Accepted41ms34852 KiB
17Wrong answer89ms39196 KiB
subtask40/10
18Wrong answer8ms30376 KiB
19Accepted17ms31084 KiB
20Accepted14ms31064 KiB
21Accepted19ms32484 KiB
22Wrong answer18ms31888 KiB
subtask50/30
23Wrong answer14ms31248 KiB
24Accepted27ms33320 KiB
25Wrong answer12ms31596 KiB
26Wrong answer10ms31728 KiB
27Wrong answer20ms32852 KiB
28Wrong answer32ms34312 KiB
29Wrong answer46ms36008 KiB
30Accepted25ms34932 KiB
31Accepted41ms39508 KiB
32Wrong answer109ms42824 KiB
subtask60/30
33Accepted64ms44980 KiB
34Accepted35ms39544 KiB
35Accepted206ms52760 KiB
36Wrong answer245ms53028 KiB
37Wrong answer246ms53288 KiB
38Wrong answer326ms56192 KiB
39Wrong answer349ms56720 KiB
40Wrong answer442ms58572 KiB
41Accepted340ms63848 KiB
42Wrong answer230ms41440 KiB