惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
腾讯CDC
博客园 - 聂微东
爱范儿
爱范儿
罗磊的独立博客
P
Proofpoint News Feed
博客园 - Franky
博客园 - 三生石上(FineUI控件)
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
Jina AI
Jina AI
Blog — PlanetScale
Blog — PlanetScale
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 司徒正美
美团技术团队
MongoDB | Blog
MongoDB | Blog
WordPress大学
WordPress大学
A
About on SuperTechFans
I
InfoQ
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Help Net Security
Microsoft Azure Blog
Microsoft Azure Blog
G
Google Developers Blog

Tifa's Blog

随笔 - 关于 C++ 模板的部分特化 随笔 - Miller-Rabin + Pollard-Rho 分解质因子的时间复杂度分析 随笔 - 批量重命名 APK 文件的 Python 脚本 VP 记录 - 2021 CCPC 哈尔滨站 VP 记录 - 2023 ICPC 亚洲区域赛 (南京) VP 记录 - 2023 CCPC 桂林站 VP 记录 - 2023 ICPC 亚洲区域赛 (网络预选赛 Ⅰ) VP 记录 - 2021 ICPC 亚洲区域赛 (澳门) 题解 - [Luogu P7486] 「Stoi2031」彩虹 拟阵简介(unfin) 题解 - [Luogu P5824] 十二重计数法 随笔 - C++ 的高维向量 | Tifa's Blog 目录 - 算法竞赛模板 | Tifa's Blog 目录 - 学术垃圾 | Tifa's Blog 比赛记录 - Codeforces Round #842 (Div. 2) 比赛记录 - Hello 2023 | Tifa's Blog 比赛记录 - Codeforces Round #841 (Div. 2) and Divide by Zero 2022 随笔 - C++ 基于标签分发的线性筛 | Tifa's Blog VP 记录 - 2022 ICPC 亚洲区域赛 (杭州) VP 记录 - 2022 ICPC 亚洲区域赛 (济南)
VP 记录 - 2023 CCPC 哈尔滨站
Tifa · 2023-11-24 · via Tifa's Blog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <bits/stdc++.h>
using namespace std;
template <class Tp>
using vec = vector<Tp>;
template <class... Ts>
void dec(Ts &...x) {
((--x), ...);
}
template <class... Ts>
void inc(Ts &...x) {
((++x), ...);
}
void solve(int t_ = 0) {
int n, m;
cin >> n >> m;
vector<vec<int>> e(n);
auto add = [&](int u, int v) { e[u].push_back(v), e[v].push_back(u); };
for (int i = 0, u, v; i < m; ++i) cin >> u >> v, --u, --v, add(u, v);
int sg = 0;
vector<int> rt, sz(n);
auto dfs = [&](auto dfs, int u) -> void {
sz[u] = 1;
for (auto v : e[u])
if (!sz[v]) dfs(dfs, v), sz[u] += sz[v];
};
auto ssg = [](int x) {
if (!x) return 0;
return x & 1 ? 1 : 2;
};
for (int i = 0; i < n; ++i)
if (!sz[i]) {
dfs(dfs, i), rt.push_back(i);
sg ^= ssg(sz[i]);
}
if (!sg) return void(cout << 0);
int ans = 0;
auto getans = [&](auto getans, int u, int fa, int ssz) -> void {
int t = ssg(ssz - sz[u]);
for (auto v : e[u])
if (v != fa) {
if (0 == (sg ^ (ssg(sz[v]) ^ ssg(ssz - sz[v])))) ++ans;
getans(getans, v, u, ssz);
t ^= ssg(sz[v]);
}
if (0 == (sg ^ t)) ++ans;
};
for (auto x : rt) {
sg ^= ssg(sz[x]);
getans(getans, x, x, sz[x]);
sg ^= ssg(sz[x]);
}
cout << ans;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cerr << fixed << setprecision(6);
int i_ = 0;
solve(i_);
return 0;
}