/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;
const ll INF = 1e18;
ll n, m, ans = 0, SZ[N];
vector<int> g[N];
bitset<N> vis, cut;
vi st;
vector<vi> C;
int tin[N], timer = 0, low[N];
void dfs(int v, int p){
vis[v] = 1;
st.pb(v);
tin[v] = low[v] = timer++;
int ch = 1;
for(int u: g[v]){
if(u == p) continue;
if(vis[u]){
low[v] = min(low[v], tin[u]);
}else{
dfs(u, v);
low[v] = min(low[v], low[u]);
if(low[u] >= tin[v]){
cut[v] = v > 1 || ch > 1;
C.pb(vi{v});
while(C.back().back() != u){
C.back().pb(st.back());
st.pop_back();
}
}
}
++ch;
}
// cerr << v << ' ' << cut[v] << '\n';
}
int cu = 0;
ll sz[N], SZ2[N];
vi ID(N);
vector<vi> T; // graph
void dfs2(int v, int p){
sz[v] = SZ[v];
for(int u: T[v]){
if(u != p){
dfs2(u, v);
sz[v] += sz[u];
}
}
// cerr << v << ' ' << SZ[v] << ' ' << sz[v] << '\n';
// cerr << v << '\n';
ll sum = 0;
for(int u: T[v]){
if(u != p){
ans -= sum * sz[u] * 4 * SZ[v];
sum += sz[u];
}
}
ans -= SZ[v] * (SZ[v] - 1) * (n - SZ2[v]);
ans -= 4 * sum * (n - sz[v]) * SZ[v];
// cerr << v << ' ' << ans << '\n';
}
void solve(){
cin >> n >> m;
for(int i = 1; i <= m; ++i){
int u, v, w; cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
ans = n * (n-1) * (n-2);
dfs(1, 1);
int id = 0;
for(int i = 1; i <= n; ++i){
if(cut[i]){
ID[i] = id++;
SZ[ID[i]] = 1;
T.pb({});
++cu;
SZ2[id - 1] = n;
}
}
for(auto c: C){
// for(int x: c){
// cerr << x << ' ';
// }
// cerr << '\n';
int node = id++;
SZ2[node] = c.size();
T.pb({});
SZ[node] = 0;
for(int x: c){
if(!cut[x]){
ID[x] = node;
SZ[node]++;
}else{
T[ID[x]].pb(node);
T[node].pb(ID[x]);
}
}
}
dfs2(0, 0);
cout << ans;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int tt = 1, aa;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(tt--){
solve();
en;
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |