QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#535828#7755. Game on a ForestlongyinWA 1ms4012kbC++20936b2024-08-28 15:24:412024-08-28 15:24:42

Judging History

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

  • [2024-08-28 15:24:42]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4012kb
  • [2024-08-28 15:24:41]
  • 提交

answer

#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

using ll = long long;
const int N = 1e5 + 5;

vector<int> edges[N];
int color[N];

int main() {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int u, v;
        cin >> u >> v;
        edges[u].emplace_back(v);
        edges[v].emplace_back(u);
    }

    function<int(int, int, int)> dfs = [&](int u, int fa, int col) -> int {
        int ans = 0;
        color[u] = col;
        for (int v : edges[u]) {
            if (v == fa)
                continue;
            ans ^= (dfs(v, u, col) + 1);
        }
        return ans == 0 ? 1 : ans;
    };

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (color[i])
            continue;
        ans ^= dfs(i, 0, i);
    }
    cout << (ans - 1 >= 0 ? ans - 1 : 0) << endl;

    return 0;
}

详细

Test #1:

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

input:

3 1
1 2

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3628kb

input:

4 3
1 2
2 3
3 4

output:

3

result:

ok 1 number(s): "3"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3992kb

input:

100000 1
4647 17816

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 1ms
memory: 3888kb

input:

100000 2
64075 72287
63658 66936

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 4012kb

input:

100000 3
59930 72281
31689 59132
20469 33165

output:

1

result:

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