QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#766237 | #7755. Game on a Forest | wenqizhi | WA | 1ms | 4596kb | C++20 | 1.2kb | 2024-11-20 16:42:28 | 2024-11-20 16:42:33 |
Judging History
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'