QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#258414 | #7755. Game on a Forest | ucup-team2307# | WA | 1ms | 5936kb | C++20 | 1.3kb | 2023-11-19 17:52:59 | 2023-11-19 17:53:01 |
Judging History
answer
#include<bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
struct DSU {
vector<int> e;
DSU(int n) : e(n, -1) {}
int find(int v) { return e[v] < 0 ? v : e[v] = find(e[v]); }
bool join(int u, int v) {
u = find(u), v = find(v);
if(u == v) return 0;
if(-e[u] < -e[v]) swap(u, v);
e[u] += e[v];
e[v] = u;
return 1;
}
};
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<vector<int>> g(n);
for(int u, v, i = 0; i < m; i++) {
cin >> u >> v;
g[--u].push_back(--v);
g[v].push_back(u);
}
vector<int> vis(n);
int even, sz;
auto dfs = [&](auto self, int v, int p) -> void {
vis[v] = 1;
sz++;
even += g[v].size() % 2 == 0;
for(auto i : g[v]) if(i ^ p) {
self(self, i, v);
}
};
int val = 0, ans = 0;
for(int i = 0; i < n; i++)
if(!vis[i]) {
even = 0, sz = 0, dfs(dfs, i, i);
if(sz % 2 == 0) {
val ^= 2;
ans += sz - 1;
} else {
val ^= 1;
ans += even;
}
}
if(!val) ans = 0;
cout << ans << '\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3444kb
input:
3 1 1 2
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3420kb
input:
4 3 1 2 2 3 3 4
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 5936kb
input:
100000 1 4647 17816
output:
99999
result:
wrong answer 1st numbers differ - expected: '1', found: '99999'