This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define ET cout << "\n"
#define F first
#define S second
#define MP make_pair
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;};
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
vector<ll> G[100005],BG[100005];
ll low[100005],dfn[100005],bln[100005],avsub[100005],sub[100005],nBcc,dft;
ll ans1,ans2,n;
stack<ll> st;
void dfs(int u,int f)
{
ll usq=0;
low[u]=dfn[u]=++dft,sub[u]=1;
st.push(u);
vector<int> v;
for(ll i:G[u])
if(i!=f)
if(!dfn[i])
{
dfs(i,u),sub[u]+=sub[i];
if(low[i]>=dfn[u])
{
ll sz=0,sq=0;
avsub[u]+=sub[i],usq+=sub[i]*sub[i],++nBcc;
for(int x=-1;x!=i;)
{
x=st.top(),st.pop(),bln[x]=nBcc,++sz;
sq+=avsub[x]*avsub[x];
}
ans1+=sz*(sz-1)*(sz-2),ans1+=sz*(sz-1),ans2+=sz*(sz-1)*(n-sz);
sq+=(n-sub[i])*(n-sub[i]),ans1+=sz*((n-sz)*(n-sz)-sq);
}
else
low[u]=min(low[u],low[i]);
}
else if(dfn[u]>dfn[i])
low[u]=min(low[u],dfn[i]);
ans1+=avsub[u]*avsub[u]-usq;
}
int main()
{jizz
ll m,a,b;
cin >> n >> m;
while(m--)
cin >> a >> b,G[a].pb(b),G[b].pb(a);
dfs(1,1);
cout << ans1+ans2*2 << "\n";
}
Compilation message (stderr)
count_triplets.cpp: In function 'void dfs(int, int)':
count_triplets.cpp:28:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
if(i!=f)
^
# | 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... |