#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 100001;
int n, m, st[N], low[N], k, ans = 0, tot = 0, sz[N], dp[N], timer = 0;
bool vis[N << 1];
vector<int> adj[N], g[N << 1], stk;
void dfs(int u) {
st[u] = low[u] = ++timer;
stk.push_back(u);
for (int 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[x].push_back(k);
g[k].push_back(x);
// cout << x << " --> " << k << '\n';
}
g[u].push_back(k);
g[k].push_back(u);
// cout << u << " --> " << k << '\n';
}
}
low[u] = min(low[u], st[v]);
}
}
void compute(int u, int p) {
vis[u] = 1;
int sum = 0, sdp = 0;
if (u <= n) sz[u] = 1;
for (int v : g[u]) {
if (v == p) continue;
compute(v, u);
sz[u] += sz[v];
if (u <= n) ans += dp[v] * 4;
dp[u] += dp[v];
sdp += dp[v];
sum += sz[v];
}
if (u <= n) {
dp[u] += (sz[u] - 1);
}
ans += (sum * sum) * (n - sz[u] - 1);
for (int v : g[u]) {
if (v == p) continue;
// ans += (sdp - dp[v]) * (sz[v]) * 2;
ans -= sz[v] * sz[v] * (n - sz[u] - 1);
}
}
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++) if (!st[i]) dfs(i);
for (int i = 1; i <= n; i++) if (!vis[i]) compute(i, -1);
cout << n * (n - 1) * (n - 2) - ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
30672 KB |
Output is correct |
2 |
Correct |
45 ms |
30664 KB |
Output is correct |
3 |
Incorrect |
47 ms |
27084 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
22640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
22608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |