QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#669339 | #7755. Game on a Forest | lllei# | WA | 2ms | 6108kb | C++23 | 1.7kb | 2024-10-23 18:15:02 | 2024-10-23 18:15:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> e(n);
for (int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
--u, --v;
e[u].push_back(v);
e[v].push_back(u);
}
vector<bool> vis(n);
vector<int> siz(n);
auto dfs = [&](auto &&self, int u) -> void {
vis[u] = true;
siz[u] = 1;
for (int v : e[u]) {
if (vis[v]) {
continue;
}
self(self, v);
siz[u] += siz[v];
}
};
auto get = [&](const int &x) {
return (x % 2) ? 1 : 2;
};
int res = 0;
for (int i = 0; i < n; ++i) {
if (!vis[i]) {
dfs(dfs, i);
res ^= get(siz[i]);
}
}
int ans = 0;
int tot = 0;
auto dfs1 = [&](auto &&self, int u) -> void {
vis[u] = true;
int t1 = 0;
for (int v : e[u]) {
if (vis[v]) {
continue;
}
if ((res ^ get(siz[v]) ^ get(n - siz[v])) == 0) {
ans++;
}
self(self, v);
t1 ^= get(siz[v]);
}
if (tot - siz[u] > 0) {
t1 ^= get(tot - siz[u]);
}
if ((t1 ^ res) == 0) {
ans++;
}
};
vis.assign(n, false);
for (int i = 0; i < n; ++i) {
if (!vis[i]) {
res ^= get(siz[i]);
tot = siz[i];
dfs1(dfs1, i);
res ^= get(siz[i]);
}
}
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3788kb
input:
3 1 1 2
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
4 3 1 2 2 3 3 4
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: 0
Accepted
time: 2ms
memory: 5956kb
input:
100000 1 4647 17816
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 2ms
memory: 5940kb
input:
100000 2 64075 72287 63658 66936
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 0ms
memory: 6044kb
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: 5956kb
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: 0
Accepted
time: 2ms
memory: 6108kb
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:
200
result:
ok 1 number(s): "200"
Test #8:
score: -100
Wrong Answer
time: 2ms
memory: 5988kb
input:
100000 1001 298 77037 4590 12413 23983 44856 15445 16769 81205 99801 62678 90775 7513 11129 27455 63264 39986 44211 61692 72309 60465 67632 66675 72861 4281 28582 26376 65551 9751 60666 4388 47945 1077 1132 53716 62874 39894 55139 28957 63412 41201 89573 6166 10477 2322 23039 24579 87570 16337 90895...
output:
957
result:
wrong answer 1st numbers differ - expected: '1001', found: '957'