QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#278351#5558. Formula Flatlandjzh#WA 0ms28912kbC++202.3kb2023-12-07 15:05:122023-12-07 15:05:13

Judging History

你现在查看的是最新测评结果

  • [2023-12-07 15:05:13]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:28912kb
  • [2023-12-07 15:05:12]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

struct Point {
public:
    ll x, y;

    ll operator^(Point &a) {
        return x * a.y - y * a.x;
    }
};

struct argcmp {
    bool operator()(Point &a, Point &b) {
        auto quad = [](Point &a) {
            if (a.y < 0) return 1;
            if (a.y > 0) return 4;
            if (a.x < 0)return 5;
            if (a.x > 0)return 3;
        };
        int qa = quad(a), qb = quad(b);
        if (qa != qb)return qa < qb;
        ll t = a ^ b;
        return t > 0;
    }
};

const int N = 7e5 + 5;

struct E {
    int u, v;
    Point a;
} e[N];
int fa[N];
int siz[N];

int find(int u) {
    while (fa[u] != u) u = fa[u] = fa[fa[u]];
    return u;
}

int x[N], y[N];
vector<int> G[N];

int main() {
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> y[i];
    }

    for (int i = 0; i < 2 * m; i += 2) {
        int u, v;
        cin >> u >> v;
        Point a = {x[u] - x[v], y[u] - y[v]};
        Point b = {x[v] - x[u], y[v] - y[u]};
        e[i] = {u, v, b};
        e[i + 1] = {v, u, a};
        G[u].push_back(i);
        G[v].push_back(i + 1);
        fa[i] = i, fa[i + 1] = i + 1;
        siz[i] = siz[i + 1] = 1;
    }

    for (int i = 1; i <= n; i++) {
        vector<int> eids = G[i];

        auto cmp = [&](int u, int v) {
            argcmp cp;
            return cp(e[u].a, e[v].a);
        };

        sort(eids.begin(), eids.end(), cmp);

        for (int j = 0; j < eids.size(); j++) {
            int nxt = (j + 1) % eids.size();
            int eu = eids[j] ^ 1, ev = eids[nxt];

            // cout <<" conn " << eu<<" and " << ev << endl;
//            cout <<" siz " << siz[find(eu)] <<" , " << siz[find(ev)] << endl;
//            cout <<" f " << find(eu) <<","<< find(ev) << endl;
            if (find(eu) != find(ev)) {

                siz[find(ev)] += siz[find(eu)];
                fa[find(eu)] = find(ev);
                // cout <<" siz " << find(ev) <<" is " << siz[find(ev)] << endl;
            }
        }
    }
    int ans = 4;
    for (int i = 0; i < 2 * m; i++) {
        ans = min(ans, siz[find(i)]);
        cout <<" siz " << find(i) <<" -> " << siz[find(i)] << endl;
    }

    cout << ans << endl;


}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 28912kb

input:

4 6
0 0
3 0
0 3
1 1
1 2
1 3
1 4
2 3
2 4
3 4

output:

 siz 6 -> 3
 siz 4 -> 3
 siz 10 -> 3
 siz 6 -> 3
 siz 4 -> 3
 siz 10 -> 3
 siz 6 -> 3
 siz 8 -> 3
 siz 8 -> 3
 siz 4 -> 3
 siz 10 -> 3
 siz 8 -> 3
3

result:

wrong answer 1st lines differ - expected: '3', found: ' siz 6 -> 3'