#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 10;
vector<int> adj[N], g[N << 1], stk;
int n, m, st[N], low[N], timer = 0, k, we[N << 1], sz[N << 1], ans = 0;
void dfs(int u) {
low[u] = st[u] = ++timer;
stk.push_back(u);
for (auto& v : adj[u]) {
if (!st[v]) {
dfs(v);
low[u] = min(low[u], low[v]);
if (low[v] == st[u]) {
++k;
for (int x = -1; x != v; stk.pop_back()) {
x = stk.back();
g[k].push_back(x);
g[x].push_back(k);
we[k]++;
}
g[k].push_back(u);
g[u].push_back(k);
we[k]++;
}
}
low[u] = min(low[u], st[v]);
}
}
void comp(int u, int p) {
sz[u] = (u <= n);
int sum = 0, ch = 0;
for (int v : g[u]) {
if (v == p) continue;
++ch;
comp(v, u);
sz[u] += sz[v];
sum += sz[v];
}
if (!ch) ans--;
for (int v : g[u]) if (v != p) ans += we[u] * sz[v] * (sum - sz[v]);
ans += we[u] * sum * (n - sum);
}
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
k = n;
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i = 1; i <= n; i++) we[i] = -1;
dfs(1);
comp(1, -1);
cout << ans - 1 << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
7504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
7504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
76 ms |
28860 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
7504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
74 ms |
23880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
7504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
77 ms |
23876 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
7504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
7504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |