QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#712200 | #7755. Game on a Forest | tassei903# | WA | 0ms | 3556kb | C++23 | 1.5kb | 2024-11-05 14:53:38 | 2024-11-05 14:53:39 |
Judging History
answer
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
#define sz(x) (int)(x).size()
#define rep(i, l, r) for (int i = l; i < (r); i++)
#define rrep(i, l, r) for(int i = (int)(r)-1; i >= (int)(l); i--)
#define all(x) begin(x), end(x)
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
void solve() {
std::cin.tie(0)->sync_with_stdio(0);
int n, m;cin >> n >> m;
vector<vi> g(n);
rep(i, 0, m) {
int u, v;cin >> u >> v;
u--;
v--;
g[u].emplace_back(v);
g[v].emplace_back(u);
}
vector<int> seen(n, 0);
auto dfs = [&](auto self, int v, int p)->pii {
seen[v] = 1;
int res = 1;
int leaf = (sz(g[v]) == 1);
for (int u : g[v]) {
if (u == p)continue;
auto [r, l] = self(self, u, v);
res += r;
leaf += l;
}
return {res, leaf};
};
array<int, 2> s, c, l;
rep(i, 0, n) {
if (seen[i])continue;
auto [rr, ll] = dfs(dfs, i, -1);
s[rr%2] += rr;
c[rr%2] += 1;
l[rr%2] += ll;
}
if (c[0] % 2 == 0 && c[1] % 2 == 0) {
cout << 0 << endl;
}
else if (c[0] % 2 && c[1] % 2) {
cout << l[0] + l[1] << endl;
}
else if (c[0] % 2 && c[1] % 2 == 0) {
cout << m << endl;
}
else {
cout << n - l[0] - l[1] << endl;
}
}
int main() {
int T = 1;
while (T--)solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3556kb
input:
3 1 1 2
output:
1
result:
wrong answer 1st numbers differ - expected: '2', found: '1'