#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;
vi graph_tree[200005];
vi graph[1000015];
int pre[100005];
int low[100005];
int cur_pre = 0;
ll subtree[200005];
bool odw[200005];
int cur_comp = 1;
ll ans = 0;
int n,m;
ll tree_siz = 0;
stack<int> st;
void calc_pre(int v, int pop)
{
tree_siz++;
odw[v] = 1;
pre[v] = cur_pre++;
low[v] = pre[v];
forall(it,graph[v])
{
if(odw[it] == 1)
{
if(it != pop)
{
// cout << v << " " << it << " " << pop << " low\n";
low[v] = min(low[v],pre[it]);
}
}
else
{
calc_pre(it,v);
low[v] = min(low[v],low[it]);
}
}
}
void calc_comps(int v, int pop)
{
st.push(v);
odw[v] = 0;
forall(it,graph[v])
{
if(odw[it] == 0) continue;
calc_comps(it,v);
if(low[it] >= pre[v])
{
graph_tree[v].pb(cur_comp+n);
while(siz(graph_tree[cur_comp+n]) == 0 || graph_tree[cur_comp+n][siz(graph_tree[cur_comp+n])-1] != it)
{
graph_tree[cur_comp+n].pb(st.top());
st.pop();
}
cur_comp++;
}
}
}
int dfs_ans(int v, int pop)
{
if(v <= n) subtree[v] = 1;
odw[v] = 1;
// cout << v << " v\n";
forall(it,graph_tree[v])
{
if(it != pop)
{
subtree[v] += dfs_ans(it,v);
if(v > n)
{
ans -= siz(graph_tree[v]) * subtree[it] * (subtree[it]-1);
}
}
}
if(v > n)
{
ans -= siz(graph_tree[v]) * (tree_siz - subtree[v]) * (tree_siz - subtree[v]-1);
}
return subtree[v];
}
int main()
{
//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//random_start();
cin >> n >> m;
if(n <= 2)
{
cout << "0\n";
return 0;
}
rep(i,m)
{
int a,b;
cin >> a >> b;
graph[a].pb(b);
graph[b].pb(a);
}
rep2(i,1,n)
{
if(odw[i] == 0)
{
tree_siz = 0;
calc_pre(i,i);
ans += tree_siz * (tree_siz-1) * (tree_siz-2);
calc_comps(i,i);
dfs_ans(i,i);
}
}
cout << ans << "\n";
}
# | 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... |