QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#287918 | #7755. Game on a Forest | yllcm# | WA | 2ms | 7440kb | C++20 | 1.3kb | 2023-12-21 10:41:52 | 2023-12-21 10:41:52 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define db double
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define FR first
#define SE second
using namespace std;
inline int read() {
int x = 0; bool op = false;
char c = getchar();
while(!isdigit(c))op |= (c == '-'), c = getchar();
while(isdigit(c))x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return op ? -x : x;
}
const int N = 1e5 + 10;
int n, m;
int vis[N], f[N], sz[N];
vector<int> G[N];
int find(int x) {return f[x] == x ? x : f[x] = find(f[x]);}
void unionn(int x, int y) {
x = find(x); y = find(y);
if(x == y)return ;
f[y] = x; sz[x] += sz[y];
return ;
}
int main() {
n = read(); m = read();
for(int i = 1; i <= n; i++)f[i] = i, sz[i] = 1;
for(int i = 1; i <= m; i++) {
int u = read(), v = read();
G[u].pb(v); G[v].pb(u);
unionn(u, v);
}
int co = 0, ce = 0;
for(int i = 1; i <= n; i++)if(find(i) == i)
((sz[i] & 1) ? co : ce) ^= 1;
if(!co && !ce)return puts("0"), 0;
int ans = 0;
for(int i = 1; i <= n; i++) {
if(find(i) != i)continue;
vis[i] = true;
if(co && ce)ans += (~sz[i] & 1) * sz[i];
else if(co)ans += (sz[i] & 1) * (2 * sz[i] - 1);
else ans += (~sz[i] & 1) * (sz[i] - 1);
}
printf("%d\n", ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 7156kb
input:
3 1 1 2
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 1ms
memory: 6464kb
input:
4 3 1 2 2 3 3 4
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: 0
Accepted
time: 0ms
memory: 7440kb
input:
100000 1 4647 17816
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 6744kb
input:
100000 2 64075 72287 63658 66936
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 2ms
memory: 7280kb
input:
100000 3 59930 72281 31689 59132 20469 33165
output:
3
result:
ok 1 number(s): "3"
Test #6:
score: 0
Accepted
time: 0ms
memory: 6740kb
input:
100000 10 20391 78923 27822 80617 21749 25732 12929 79693 42889 52515 59064 99869 29031 41875 4463 17813 13407 42498 19120 20957
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 7384kb
input:
99999 101 34378 94161 67696 83255 24557 25591 11476 58475 5684 38157 33843 35321 9046 24028 14293 77681 587 42098 9402 27228 6999 13980 27118 84005 3622 8353 13545 51621 16998 63647 32912 53178 15206 15815 56517 86335 5563 93770 153 278 11242 41753 75098 76792 1695 22836 25936 33352 2765 6778 19597 ...
output:
198
result:
wrong answer 1st numbers differ - expected: '200', found: '198'