#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MX = 200005;
int n, m, bcc;
int num[MX], low[MX];
int sz[MX], f[MX][3];
vector<int> G[MX];
vector<int> T[MX];
void buildBCT(int u){
static int peak = 0;
static stack<int> st;
num[u] = low[u] = ++peak;
st.push(u);
for(int v: G[u]){
if(!num[v]){
buildBCT(v);
low[u] = min(low[u], low[v]);
if(low[v] == num[u]){
bcc++;
T[u].push_back(n + bcc);
do{
sz[n + bcc]++;
T[n + bcc].emplace_back(st.top());
st.pop();
} while(T[n + bcc].back() != v);
}
}
else low[u] = min(low[u], num[v]);
}
}
int c2(int x){
return x * (x - 1) / 2;
}
int c3(int x){
return x * (x - 1) * (x - 2) / 6;
}
long long solve(int u){
static long long ans = 0;
if(u <= n) f[u][1] += 1;
for(int v: T[u]){
solve(v);
ans += f[u][1] * f[v][2] + f[u][2] * f[v][1];
f[u][1] += f[v][1];
f[u][2] += f[v][2];
if(u <= n) f[u][2] += f[v][1];
else f[u][2] += f[v][1] * (sz[u] - 1);
}
return ans;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for(int i=1; i<=m; i++){
int u, v;
cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
int ans = 0;
for(int i=1; i<=n; i++) if(!num[i]){
buildBCT(i);
ans = max(ans, solve(i) * 2);
}
cout << ans;
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... |