QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#262043#7755. Game on a ForestSatsuki#WA 2ms7868kbC++171.5kb2023-11-23 14:58:262023-11-23 14:58:27

Judging History

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

  • [2023-11-23 14:58:27]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:7868kb
  • [2023-11-23 14:58:26]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = l; i <= r; ++ i)
// #define int long long
using namespace std;
const int MAXN = 1e6 + 10, mod = 998244353;

int read()
{
    char cc(getchar()); int cn(0), flus(1);
    while(!isdigit(cc)) {if(cc == '-') flus = -flus; cc = getchar();}
    while(isdigit(cc)) cn = cn * 10 + cc - 48, cc = getchar();
    return cn * flus;
}

struct edge
{
    int to, next;
} e[MAXN << 1];

int n, m, head[MAXN], tot;
int col[MAXN], cnt, pcs[MAXN];

void add(int u, int v)
{
    e[++tot].next = head[u];
    head[u] = tot;
    e[tot].to = v;
}

void dfs(int u, int fa)
{
    col[u] = cnt;
    pcs[cnt] ++;
    for(int i = head[u]; i; i = e[i].next)
    {
        int v = e[i].to;
        if(v == fa) continue;
        dfs(v, u);
    }
}

signed main()
{
    n = read(), m = read();
    rep(i, 1, m)
    {
        int u = read(), v = read();
        add(u, v);
        add(v, u);
    }
    rep(i, 1, n)
    {
        if(!col[i])
        {
            col[i] = ++cnt;
            dfs(i, 0);
        }
    }
    int ans(0);
    if(cnt == 1)
    {
        if(pcs[1] & 1) ans = 1;
        else ans = pcs[1] - 1;
    }
    else
    {
        rep(i, 1, cnt)
        {
            if(pcs[i] & 1)
            {
                ans +=  pcs[i] - 1;
            }
            else
            {
                ans += pcs[i];
            }
        }
    }
    cout << ans;
    return 0;
}

詳細信息

Test #1:

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

input:

3 1
1 2

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

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

input:

100000 1
4647 17816

output:

2

result:

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