#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
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 |
1 |
Incorrect |
6 ms |
5112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
5112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
22736 KB |
Output is correct |
2 |
Correct |
136 ms |
22884 KB |
Output is correct |
3 |
Incorrect |
108 ms |
17700 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5112 KB |
Output is correct |
2 |
Correct |
7 ms |
5112 KB |
Output is correct |
3 |
Correct |
7 ms |
5112 KB |
Output is correct |
4 |
Correct |
7 ms |
5240 KB |
Output is correct |
5 |
Correct |
7 ms |
5240 KB |
Output is correct |
6 |
Correct |
7 ms |
5112 KB |
Output is correct |
7 |
Correct |
7 ms |
5240 KB |
Output is correct |
8 |
Correct |
7 ms |
5112 KB |
Output is correct |
9 |
Correct |
7 ms |
5244 KB |
Output is correct |
10 |
Incorrect |
6 ms |
5112 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
13872 KB |
Output is correct |
2 |
Correct |
106 ms |
13992 KB |
Output is correct |
3 |
Correct |
80 ms |
13944 KB |
Output is correct |
4 |
Correct |
87 ms |
13944 KB |
Output is correct |
5 |
Correct |
86 ms |
13984 KB |
Output is correct |
6 |
Correct |
94 ms |
18936 KB |
Output is correct |
7 |
Correct |
98 ms |
17528 KB |
Output is correct |
8 |
Correct |
82 ms |
16604 KB |
Output is correct |
9 |
Correct |
88 ms |
15608 KB |
Output is correct |
10 |
Incorrect |
75 ms |
13944 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5112 KB |
Output is correct |
2 |
Correct |
6 ms |
5116 KB |
Output is correct |
3 |
Incorrect |
7 ms |
5112 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
13916 KB |
Output is correct |
2 |
Correct |
81 ms |
13816 KB |
Output is correct |
3 |
Incorrect |
88 ms |
14428 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
5112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
5112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |