Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <vector>
- #define task "edge"
- using namespace std;
- using ld = long double;
- using ll = long long;
- const int N = 1e5 + 5;
- int n, m, low[N], num[N], l(0);
- int cnt(0), brigde(0), dp[N];
- ll ans(0);
- vector<int> adj[N], x;
- void Read()
- {
- cin >> n >> m;
- for(int i = 1; i <= m; ++i)
- {
- int u, v;
- cin >> u >> v;
- adj[u].push_back(v);
- adj[v].push_back(u);
- }
- }
- void dfs(int v, int par = 0)
- {
- low[v] = num[v] = ++l;
- dp[v] = 1;
- for(auto i : adj[v])
- if(i != par)
- {
- if(!num[i])
- {
- dfs(i, v);
- dp[v] += dp[i];
- low[v] = min(low[v], low[i]);
- if(low[i] > num[v]){
- ans += 1ll * dp[i] * (n - dp[i]) - 1;
- ++brigde;
- }
- else ans += 1ll * n * (n - 1) / 2 - m;
- }
- else {
- low[v] = min(low[v], num[i]);
- if(num[i] < num[v])
- ans += 1ll * n * (n - 1) / 2 - m;
- }
- }
- }
- void Solve()
- {
- for(int i = 1; i <= n; ++i)
- if(!num[i])
- {
- dfs(i);
- ++cnt;
- x.push_back(i);
- }
- /// special cases
- if(cnt > 2)
- {
- cout << 0;
- return;
- }
- else if(cnt == 2)
- {
- cout << (1ll * dp[x[0]] * dp[x[1]] * (m - brigde));
- return;
- }
- /// normal case
- cout << ans;
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if(fopen(task".INP", "r"))
- {
- freopen(task".INP", "r", stdin);
- freopen(task".OUT", "w", stdout);
- }
- Read();
- Solve();
- }
Add Comment
Please, Sign In to add comment