QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#766237#7755. Game on a ForestwenqizhiWA 1ms4596kbC++201.2kb2024-11-20 16:42:282024-11-20 16:42:33

Judging History

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

  • [2024-11-20 16:42:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4596kb
  • [2024-11-20 16:42:28]
  • 提交

answer

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

#define ll long long
#define ull unsigned long long

int read()
{
    int x = 0; bool f = false; char c = getchar();
    while(c < '0' || c > '9') f |= (c == '-'), c = getchar();
    while(c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c & 15), c = getchar();
    return f ? -x : x;
}

const int N = 1e5 + 5;
int n, m;
int f[N], Size[N];
int find(int x){ return (x == f[x]) ? (f[x]) : (f[x] = find(f[x])); }
void merge(int x, int y)
{
    x = find(x), y = find(y);
    if(x == y) return ;
    if(x > y) swap(x, y);
    f[y] = x, Size[x] += Size[y];
}
int main()
{
    n = read(), m = read();
    for(int i = 1; i <= n; ++i) f[i] = i, Size[i] = 1;
    for(int i = 1; i <= m; ++i)
    {
        int u = read(), v = read();
        merge(u, v);
    }
    int cnt = 0, tot = 0;
    for(int i = 1; i <= n; ++i)
    {
        if(find(i) == i)
        {
            if(Size[i] % 2 == 0)
            {
                cnt += Size[i] - 1;
                ++tot;
            }else
            {
                cnt += Size[i];
                ++tot;
            }
        }
    }
    if(tot % 2 == 0) printf("%d\n", n + m - cnt);
    else printf("%d\n", cnt);
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3900kb

input:

3 1
1 2

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

4 3
1 2
2 3
3 4

output:

3

result:

ok 1 number(s): "3"

Test #3:

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

input:

100000 1
4647 17816

output:

99999

result:

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