QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#258414#7755. Game on a Forestucup-team2307#WA 1ms5936kbC++201.3kb2023-11-19 17:52:592023-11-19 17:53:01

Judging History

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

  • [2023-11-19 17:53:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5936kb
  • [2023-11-19 17:52:59]
  • 提交

answer

#include<bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
struct DSU {
    vector<int> e;
    DSU(int n) : e(n, -1) {}
    int find(int v) { return e[v] < 0 ? v : e[v] = find(e[v]); }
    bool join(int u, int v) {
        u = find(u), v = find(v);
        if(u == v) return 0;
        if(-e[u] < -e[v]) swap(u, v);
        e[u] += e[v];
        e[v] = u;
        return 1;
    }
};
int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    for(int u, v, i = 0; i < m; i++) {
        cin >> u >> v;
        g[--u].push_back(--v);
        g[v].push_back(u);
    }
    vector<int> vis(n);
    int even, sz;
    auto dfs = [&](auto self, int v, int p) -> void {
        vis[v] = 1;
        sz++;
        even += g[v].size() % 2 == 0;
        for(auto i : g[v]) if(i ^ p) {
            self(self, i, v);
        }
    };
    int val = 0, ans = 0;
    for(int i = 0; i < n; i++) 
        if(!vis[i]) {
            even = 0, sz = 0, dfs(dfs, i, i);
            if(sz % 2 == 0) {
                val ^= 2;
                ans += sz - 1;
            } else {
                val ^= 1;
                ans += even;
            }
        }
    if(!val) ans = 0;
    cout << ans << '\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3444kb

input:

3 1
1 2

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3420kb

input:

4 3
1 2
2 3
3 4

output:

3

result:

ok 1 number(s): "3"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 5936kb

input:

100000 1
4647 17816

output:

99999

result:

wrong answer 1st numbers differ - expected: '1', found: '99999'