QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#576005 | #7755. Game on a Forest | SCUTkk | WA | 2ms | 7184kb | C++20 | 1.8kb | 2024-09-19 17:52:04 | 2024-09-19 17:52:04 |
Judging History
answer
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m;
std::cin >> n >> m;
std::vector<std::vector<int>> adj(n);
std::vector<std::pair<int, int>> edge(m);
for (int i = 0; i < m; i++) {
int u, v;
std::cin >> u >> v;
u--, v--;
adj[u].emplace_back(v);
adj[v].emplace_back(u);
edge[i] = {u, v};
}
std::vector<int> sz(n), sg(n), f(n, -1), dep(n);
auto dfs = [&](auto dfs, int x, int fa, int rt) -> void {
f[x] = rt;
sz[x] = 1;
for (auto y : adj[x]) {
if (y == fa)
continue;
dep[y] = dep[x] + 1;
dfs(dfs, y, x, rt);
sz[x] += sz[y];
}
sg[x] = (sz[x] & 1) ? 1 : 2;
};
int tot = 0;
for (int i = 0; i < n; i++) {
if (f[i] == -1) {
dfs(dfs, i, -1, i);
tot ^= sg[i];
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
int tmp = tot;
for (auto j : adj[i]) {
if (j == f[i])
continue;
tmp ^= sg[j];
}
tmp ^= sg[f[i]];
if (f[i] != i)
tmp ^= ((sz[f[i]] - sz[i]) & 1) ? 1 : 2;
if (!tmp)
ans++;
}
for (auto [u, v] : edge) {
if (dep[v] < dep[u])
std::swap(u, v);
int tmp = tot;
tmp ^= sg[f[v]] ^ sg[v] ^ (((sz[f[v]] - sz[v]) & 1) ? 1 : 2);
// std::cerr << tot << " " << f[v] << " " << v << " " << sz[f[v]] << " " << sz[v] << "\n";
// std::cerr << sg[f[v]] << " " << sg[v] << " " << (((sz[f[v]] - sz[v]) & 1) ? 1 : 2) << "\n";
if (!tmp)
ans++;
}
std::cout << ans << "\n";
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
input:
3 1 1 2
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3884kb
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: 7040kb
input:
100000 1 4647 17816
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 2ms
memory: 7012kb
input:
100000 2 64075 72287 63658 66936
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 2ms
memory: 7104kb
input:
100000 3 59930 72281 31689 59132 20469 33165
output:
3
result:
ok 1 number(s): "3"
Test #6:
score: 0
Accepted
time: 2ms
memory: 7060kb
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: 7184kb
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:
199
result:
wrong answer 1st numbers differ - expected: '200', found: '199'