#include <bits/stdc++.h>
using namespace std;
#define N 200010
#define ll long long
#define fs first
#define sc second
#define ii pair<int,int>
#define pb push_back
ll ans=0;
ll cc,times,num[N],low[N],n,m,ktr[N],dem,sz[N],child[N];
vector<int>g[N],edge[N];
stack<int>st;
void visit(int u)
{
num[u]=low[u]=++times;
for(auto v:g[u])
if(num[v]!=0)
{
low[u]=min(low[u],num[v]);
}else
{
st.push(u);
visit(v);
low[u]=min(low[u],low[v]);
if(low[v]==num[u])
{
int k;
dem++;
do{
k=st.top();
st.pop();
if(ktr[k]!=dem)
{
sz[dem]++;
ktr[k]=dem;
edge[dem].pb(k);
edge[k].pb(dem);
// cout<<k<<" "<<dem<<endl;
}
}while(k!=u);
}
}
st.push(u);
}
void build(int u,int p)
{
ktr[u]=1;
child[u]=(u<=n);
//cout<<u<<" "<<child[u]<<endl;
for(auto v:edge[u])
if(v!=p)
{
build(v,u);
child[u]+=child[v];
}
}
void DFS(int u,int p)
{
ktr[u]=1;
if(u<=n)
{
ll sum=cc-1;
for(auto v:edge[u])
if(v!=p)
{
sum-=child[v];
ans+=1ll*sum*child[v];
// cout<<sum<<" "<<child[v]<<endl;
}
}else
{
ll sum=cc;
for(auto v:edge[u])
if(v!=p)
{
sum-=child[v];
ans+=1ll*sum*child[v]*(sz[u]-2);
// cout<<u<<" "<<sum<<" "<<child[v]<<" "<<sz[u]-2<<" "<<sum*child[v]*(sz[u]-2)<<endl;
// cout<<u<<" "<<sum<<" "<<child[v]<<" "<<sz[u]<<endl;
}
}
//cout<<u<<" "<<ans*2<<endl;
for(auto v:edge[u])
if(v!=p)
DFS(v,u);
}
int main()
{
#ifdef SKY
freopen("A.inp","r",stdin);
freopen("A.out","w",stdout);
#endif // SKY
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m;
for(int i=1;i<=m;i++)
{
int u,v;
cin>>u>>v;
g[u].pb(v);
g[v].pb(u);
}
dem=n;
for(int i=1;i<=n;i++)
if(num[i]==0)
visit(i);
// cout<<dem<<endl;
memset(ktr,0,sizeof(ktr));
for(int i=1;i<=n;i++)
if(ktr[i]==0)
build(i,0);
memset(ktr,0,sizeof(ktr));
for(int i=1;i<=n;i++)
if(ktr[i]==0)
{
cc=child[i];
DFS(i,0);
break;
}
cout<<ans*2;
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... |