Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include<cstdio>
- #include<vector>
- #include<string>
- #include<iostream>
- #include<algorithm>
- #include<map>
- #include<iterator>
- #include<set>
- #include<stack>
- #include<queue>
- #include<fstream>
- #include<iomanip>
- #include <unordered_map>
- #include <unordered_set>
- #include <numeric>
- #include<cmath>
- #include<list>
- #include <sstream>
- using namespace std;
- #define FOR(i,a,b) for (int i = (a); i < (b); i++)
- #define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
- #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
- #define FILL(a,value) memset(a, value, sizeof(a))
- #define SZ(a) (int)a.size()
- #define ALL(a) a.begin(), a.end()
- #define PB push_back
- #define MP make_pair
- typedef long long LL;
- typedef vector<int> VI;
- typedef pair<int, int> PII;
- const double PI = acos(-1.0);
- const int INF = 1000 * 1000 * 1000 + 7;
- const LL LINF = INF * (LL)INF;
- const int SIZE = 1000 * 1000;
- vector<int> g[SIZE];
- int mit[SIZE];
- int numb[SIZE][2];
- PII e[SIZE];
- int n, m;
- void dfs(int v)
- {
- if (mit[v])
- {
- return;
- }
- mit[v] = 1;
- FOR(i, 0, g[v].size())
- {
- dfs(g[v][i]);
- }
- }
- bool isBinded()
- {
- dfs(0);
- FOR(i, 0, n)
- {
- if (!mit[i]) {
- return false;
- }
- }
- return true;
- }
- int main()
- {
- //freopen("in.txt", "r", stdin);
- ios::sync_with_stdio(false); cin.tie(0);
- cin >> n >> m;
- FOR(i, 0, m)
- {
- int x, y;
- cin >> x >> y;
- x--; y--;
- e[i] = MP(x, y);
- g[x].push_back(y);
- g[y].push_back(x);
- }
- if (!isBinded())
- {
- cout << 0 << endl;
- return 0;
- }
- int numbOdd = 0;
- FOR(i, 0, n)
- {
- bool hasLoop = 0;
- FOR(j, 0, g[i].size())
- {
- if (i == g[i][j])
- {
- hasLoop = 1;
- }
- bool odd = g[g[i][j]].size() & 1;
- numb[i][odd]++;
- }
- if (hasLoop)
- {
- numb[i][g[i].size() & 1]--;
- }
- if (g[i].size() & 1){
- numbOdd++;
- }
- }
- vector<int> edgs(3, 0);
- FOR(i, 0, m)
- {
- int sa = g[e[i].first].size() & 1,
- sb = g[e[i].second].size() & 1;
- edgs[sa + sb]++;
- }
- LL res = 0;
- //FOR(i, 0, n)
- //{
- // cout << i << ": " << numb[i][0] << " " << numb[i][1] << endl;
- //}
- //FOR(i, 0, 3)
- //{
- // cout << edgs[i] << endl;
- //}
- FOR(i, 0, m)
- {
- //FOR(j, 0, n)
- //{
- // cout << j << ": " << numb[j][0] << " " << numb[j][1] << endl;
- //}
- auto temp = edgs;
- int tempNumbOdd = numbOdd;
- int sa = g[e[i].first].size() & 1,
- sb = g[e[i].second].size() & 1;
- if (e[i].first != e[i].second)
- {
- tempNumbOdd += (sa ? -1 : 1);
- }
- if (e[i].first != e[i].second)
- {
- tempNumbOdd += (sb ? -1 : 1);
- }
- numb[e[i].first][sb]--;
- numb[e[i].second][sa]--;
- FOR(j, 0, 2)
- {
- temp[sa + j] -= numb[e[i].first][j];
- temp[sb + j] -= numb[e[i].second][j];
- }
- temp[sa + sb]--;
- //cout << sa << " " << sb << endl;
- //cout << e[i].first << " " << e[i].second << ": " << endl;
- //FOR(j, 0, 3)
- //{
- // cout << temp[j] << " ";
- //}
- //cout << endl;
- //cout << tempNumbOdd << endl;
- sa ^= 1;
- sb ^= 1;
- //cout << sa << " " << sb << endl;
- FOR(j, 0, 2)
- {
- temp[sa + j] += numb[e[i].first][j];
- temp[sb + j] += numb[e[i].second][j];
- }
- //temp[sa + sb ^ 1]--;
- //temp[sb + sa ^ 1]--;
- //cout << e[i].first << " " << e[i].second << ": " << endl;
- //FOR(j, 0, 3)
- //{
- // cout << temp[j] << " ";
- //}
- //cout << endl;
- if (tempNumbOdd == 4)
- {
- res += temp[2];
- }
- else {
- if (tempNumbOdd == 2) {
- res += temp[2] + temp[1];
- }
- else {
- if (tempNumbOdd == 0) {
- res += temp[0] + temp[1];
- }
- }
- }
- sa ^= 1;
- sb ^= 1;
- numb[e[i].first][sb]++;
- numb[e[i].second][sa]++;
- }
- cout << res /2 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement