//#pragma GCC optimize("Ofast,unroll-loops,O3")
//#pragma GCC optimize("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma,tune=native")
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//#pragma pack(1)
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define int long long
#define pii pair<int,int>
#define x first
#define y second
#define N 100015
using namespace std;
//using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> order_multiset;
//typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> order_set;
int n,m,dfn[N],low[N],boss[N],sz[N],cont[N],nbcc=0,t=0,ans=0;
stack<int>st;
vector<int>g[N],bcc[N];
vector<int>G[N];
vector<pii>edge;
void tarjan(int p,int lp){
dfn[p]=low[p]=++t;
st.push(p);
for (auto i:g[p]){
if (!dfn[i]){
tarjan(i,p);
low[p]=min(low[p],low[i]);
}
else if (i!=lp&&dfn[i]<dfn[p])
low[p]=min(low[p],dfn[i]);
}
if (dfn[p]==low[p]){
nbcc++;
for (int x=0;x!=p;st.pop()){
x=st.top(); boss[x]=nbcc; cont[nbcc]++;
bcc[nbcc].push_back(x);
}
}
}
void build(){
for (auto [a,b]:edge){
if (boss[a]!=boss[b]){
G[boss[a]].push_back(boss[b]);
G[boss[b]].push_back(boss[a]);
}
}
}
void dfs(int p,int lp){
sz[p]=cont[p];
for (auto i:G[p]){
if (i!=lp){
dfs(i,p);
sz[p]+=sz[i];
}
}
}
void dfs1(int p,int lp){
sz[p]+=sz[lp];
int tans=0;
for (auto i:G[p]){
tans=(tans+(cont[p]-1)*sz[i]*2+(cont[p]-1)*(cont[p]-2)*sz[i]*2);
tans=(tans+cont[p]*(sz[p]-cont[p]-sz[i])*sz[i]);
}
ans=(ans+tans);
for (auto i:G[p]){
if (i!=lp){
sz[p]-=sz[i];
dfs1(i,p);
sz[p]+=sz[i];
}
}
sz[p]-=sz[lp];
}
signed main(){
fast
cin>>n>>m;
for (int i=1;i<=m;i++){
int a,b; cin>>a>>b;
g[a].push_back(b);
g[b].push_back(a);
edge.push_back({a,b});
}
tarjan(1,0);
build();
dfs(1,0); dfs1(1,0);
for (int i=1;i<=nbcc;i++){
ans=(ans+cont[i]*(cont[i]-1)*(cont[i]-2));
}
cout<<ans<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
3 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7380 KB |
Output is correct |
6 |
Correct |
4 ms |
7392 KB |
Output is correct |
7 |
Incorrect |
4 ms |
7380 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
3 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7380 KB |
Output is correct |
6 |
Correct |
4 ms |
7392 KB |
Output is correct |
7 |
Incorrect |
4 ms |
7380 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
26432 KB |
Output is correct |
2 |
Correct |
78 ms |
26420 KB |
Output is correct |
3 |
Incorrect |
55 ms |
20396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7508 KB |
Output is correct |
2 |
Correct |
5 ms |
7508 KB |
Output is correct |
3 |
Correct |
5 ms |
7508 KB |
Output is correct |
4 |
Correct |
4 ms |
7508 KB |
Output is correct |
5 |
Correct |
4 ms |
7508 KB |
Output is correct |
6 |
Correct |
5 ms |
7508 KB |
Output is correct |
7 |
Correct |
4 ms |
7508 KB |
Output is correct |
8 |
Correct |
4 ms |
7508 KB |
Output is correct |
9 |
Correct |
4 ms |
7508 KB |
Output is correct |
10 |
Incorrect |
6 ms |
7380 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
93 ms |
23380 KB |
Output is correct |
2 |
Correct |
79 ms |
23352 KB |
Output is correct |
3 |
Correct |
82 ms |
23424 KB |
Output is correct |
4 |
Correct |
78 ms |
23352 KB |
Output is correct |
5 |
Correct |
106 ms |
23348 KB |
Output is correct |
6 |
Correct |
101 ms |
28532 KB |
Output is correct |
7 |
Correct |
91 ms |
26552 KB |
Output is correct |
8 |
Correct |
104 ms |
25724 KB |
Output is correct |
9 |
Correct |
94 ms |
24892 KB |
Output is correct |
10 |
Incorrect |
78 ms |
19764 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7508 KB |
Output is correct |
2 |
Correct |
4 ms |
7508 KB |
Output is correct |
3 |
Incorrect |
4 ms |
7508 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
23388 KB |
Output is correct |
2 |
Correct |
85 ms |
23164 KB |
Output is correct |
3 |
Incorrect |
81 ms |
21156 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
3 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7380 KB |
Output is correct |
6 |
Correct |
4 ms |
7392 KB |
Output is correct |
7 |
Incorrect |
4 ms |
7380 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
3 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7380 KB |
Output is correct |
6 |
Correct |
4 ms |
7392 KB |
Output is correct |
7 |
Incorrect |
4 ms |
7380 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |