-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathABC282D.cpp
More file actions
34 lines (34 loc) · 817 Bytes
/
ABC282D.cpp
File metadata and controls
34 lines (34 loc) · 817 Bytes
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
/*
* @FilePath: \c++\ABC282D.cpp
* @Author: WRT_Partisan
* @Date: 2025-12-13 14:27:50
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, m, u, v, c[200005], w, b, ans, s;
bool book[200005];
vector<int> mp[200005];
void dfs(int x, int co)
{
book[x] = 1, c[x] = co, (co ? b : w)++;
for (auto i : mp[x])
{
if (book[i] && c[i] == c[x])
cout << 0, exit(0);
else if (!book[i])
dfs(i, !co);
}
}
signed main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for (int i = 1; i <= m; i++)
cin >> u >> v, mp[u].push_back(v), mp[v].push_back(u);
for (int i = 1; i <= n; i++)
if (!book[i])
w = b = 0, dfs(i, 0), ans += w * b, s += (w + b) * (n - w - b);
cout << ans - m + s / 2;
return 0;
}