QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#270280#7755. Game on a Forestucup-team859#WA 2ms5868kbC++171.3kb2023-11-30 17:55:442023-11-30 17:55:45

Judging History

This is the latest submission verdict.

  • [2023-11-30 17:55:45]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 5868kb
  • [2023-11-30 17:55:44]
  • Submitted

answer

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int maxN = 100005;

vector <int> G[maxN];
bool used[maxN];

int dfs(int nod) {
    used[nod] = 1;
    int sz = 1;
    for (int vecin : G[nod]) {
        if (!used[vecin]) {
            sz += dfs(vecin);
        }
    }
    return sz;
}

void solve() {
    int n, m, ans = 0;
    cin >> n >> m;
    int nr = n - m;
    for (int i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    for (int i = 1; i <= n; i++) {
        if (used[i]) {
            continue;
        }
        int sz = dfs(i);
        if (nr % 2 == 1) {
            if (sz % 2 == 0) {
                ans += sz - 1;
            }
            else {
                ans += sz;
            }
        }
        else {
            if (sz % 2 == 1) {
                ans += sz - 1;
            }
            else {
                ans += sz;
            }
        }
    }
    cout << ans;
}

int main() {
#ifdef LOCAL
    freopen("test.in", "r", stdin);
    freopen("test.out", "w", stdout);
#endif // LOCAL
    int nrTeste = 1;
    //cin >> nrTeste;
    while (nrTeste--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 1
1 2

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

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: 5784kb

input:

100000 1
4647 17816

output:

99999

result:

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