QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#261740#7755. Game on a ForestzlxFTHWA 2ms6680kbC++171.5kb2023-11-23 09:55:012023-11-23 09:55:02

Judging History

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

  • [2023-11-23 09:55:02]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:6680kb
  • [2023-11-23 09:55:01]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i, a, b) for (auto cc##i = (b), i = (a); i <= cc##i; ++i)
#define per(i, a, b) for (auto cc##i = (b), i = (a); i >= cc##i; --i)
#define fi first
#define se second
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
const int N = 1e5 + 5;

int n, m, res, sum, ans, siz[N], vis[N];
vector<int> G[N];
inline int w(int s) {
    return (s & 1) ? 1 : 2;
}
void dfs1(int u, int fa) {
    vis[u] = 1, siz[u] = 1;
    for (auto v : G[u]) if (v != fa) {
        dfs1(v, u);
        siz[u] += siz[v];
    }
}
void dfs2(int u, int fa) {
    vis[u] = 1, siz[u] = 1;
    int var = res;
    for (auto v : G[u]) if (v != fa) {
        dfs2(v, u);
        siz[u] += siz[v];
        var ^= w(siz[v]);
    }
    if (fa) {
        if (!(res ^ w(siz[u]) ^ w(sum - siz[u]))) ++ans;
        var ^= w(sum - siz[u]);
    }
    if (!var) {
        ++ans;
    }
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m;
    rep(i, 1, m) {
        int u, v;
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    int res = 0;
    rep(i, 1, n) {
        if (!vis[i]) {
            dfs1(i, 0);
            res ^= w(siz[i]);
        }
    }
    memset(vis, 0, sizeof vis);
    rep(i, 1, n) {
        if (!vis[i]) {
            sum = siz[i];
            res ^= w(siz[i]);
            dfs2(i, 0);
            res ^= w(siz[i]);
        }
    }
    cout << ans << "\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 6136kb

input:

3 1
1 2

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 2ms
memory: 6172kb

input:

4 3
1 2
2 3
3 4

output:

3

result:

ok 1 number(s): "3"

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 6680kb

input:

100000 1
4647 17816

output:

99999

result:

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