QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#648446#9449. New School Termxh_team#WA 0ms3596kbC++201.3kb2024-10-17 19:01:422024-10-17 19:01:42

Judging History

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

  • [2024-10-17 19:01:42]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3596kb
  • [2024-10-17 19:01:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;


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

    int n, m;
    cin >> n >> m;
    n *= 2;

    vector<pair<int, int>> edges(m);
    for (auto &[x, y] : edges) {
        cin >> x >> y;
        x--, y--;
    }

    vector<int> par(n), h(n), c(n);
    iota(par.begin(), par.end(), 0);

    function<int(int)> find = [&](int x) {
        return x == par[x] ? x : find(par[x]);
    };

    vector<vector<int>> adj(n);
    function<void(int, int, int)> dfs = [&](int x, int pre, int o) {
        c[x] ^= o;
        for (int y : adj[x]) {
            if (y != pre) {
                dfs(y, x, o);
            }
        }
    };

    auto merge = [&](int x, int y) {
        int o = c[x] ^ c[y] ^ 1;
        x = find(x);
        y = find(y);
        adj[x].push_back(y);
        adj[y].push_back(x);
        if (h[x] >= h[y]) {
            par[y] = x;
            dfs(y, x, o);
            if (h[x] == h[y]) {
                h[x] += 1;
            }
        } else {
            par[x] = y;
            dfs(x, y, o);
        }
    };

    for (int i = m - 1; i >= 0; i--) {
        auto [x, y] = edges[i];
        if (find(x) != find(y)) {
            merge(x, y);
        }
    }
    for (int i = 0; i < n; i++) {
        cout << c[i];
    }

    return 0;
}

詳細信息

Test #1:

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

input:

2 4
1 3
2 4
1 4
1 2

output:

0111

result:

wrong answer The number of 0s must be equal to that of 1s.