#include<bits/stdc++.h>
#define fi first
#define ll long long
#define pb push_back
#define se second
using namespace std;
int n,m;
ll re=0;
int szz=0;
const int N=200009;
vector<pair<int,int>>v[N];
vector<pair<int,int>>v1[N];
ll cnt=1,t[N],num[N],a[N],low[N],bridge[N],b[N],par[N],vis[N],sz[N],bo[N];
int tt=0;
vector<int>nd;
void dfs (int x,int p)
{
nd.pb(x);
vis[x]=1;
low[x]=num[x]=++tt;
for(auto it:v[x])
{
if (num[it.first]==0)
dfs(it.first,x);
if (num[x]<low[it.first])
bridge[it.second]=1;
if (it.first!=p)
low[x]=min(low[x],low[it.first]);
}
if(low[x] == num[x]) {
int w=1;
while(nd.back() != x) {
par[nd.back()] = cnt;
nd.pop_back();w++;
}
par[nd.back()] = cnt;
nd.pop_back();
bo[cnt]=w;
cnt++;
}
}
void dfs2(int x,int p)
{
vis[x]=1;
for(auto it:v[x])
{
if(it.fi==p)continue;
if (!vis[it.first])
dfs2(it.first,x);
if (bridge[it.second]==1)
{
v1[par[x]].push_back({par[it.fi],x});
v1[par[it.fi]].push_back({par[x],it.fi});
}
}
}
void solve(int x,int p)
{
vis[x]=1;
for(auto it:v1[x])
{
if(it.fi==p)continue;
solve(it.fi,x);
sz[x]+=sz[it.fi];
}
sz[x]+=bo[x];
}
void go (int x,int p,ll up)
{
vis[x]=1;
sz[x]-=bo[x];
if(bo[x]>=3)
re+=bo[x]*(bo[x]-1)*(bo[x]-2);
re+=(up)*((bo[x])-1)*((bo[x])-1)*2;
re+=(sz[x])*(bo[x]-1)*(bo[x]-1)*2;int u=0;
for(auto it:v1[x])
{
if(it.fi==p)
{
u=it.se;
}
if(it.fi==p)continue;
re+=2*(t[x]-a[it.se])*sz[it.fi]*(bo[x]);
re+=2*a[it.se]*sz[it.fi];
a[it.se]+=sz[it.fi];
t[x]+=sz[it.fi];
go(it.fi,x,up+bo[x]+sz[x]-sz[it.fi]);
}
re+=2*up*bo[x]*(sz[x]-a[u]);
re+=2*up*a[u];
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
scanf("%d %d", &n, &m);
int x,y;
for(int i=0; i<m; i++)
{
scanf("%d %d", &x, &y);
v[x].push_back({y,i});
v[y].push_back({x,i});
}
memset (vis,0,sizeof vis);
for(int i=1;i<n+1;i++)
{
if(vis[i])continue;
dfs(i,-1);
}
memset (vis,0,sizeof vis);
for(int i=1;i<n+1;i++)
{
if(vis[i])continue;
dfs2(i,-1);
}
memset (vis,0,sizeof vis);
for(int i=1;i<cnt;i++)
{
if(vis[i])continue;
solve(i,0);
}
re=0;
memset (vis,0,sizeof vis);
for(int i=1;i<cnt;i++)
{
if(vis[i])continue;
go(i,0,0);
}
cout<<re;
}
Compilation message
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:95:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
95 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
count_triplets.cpp:99:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
99 | scanf("%d %d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
11392 KB |
Output is correct |
2 |
Correct |
7 ms |
11392 KB |
Output is correct |
3 |
Correct |
7 ms |
11392 KB |
Output is correct |
4 |
Correct |
7 ms |
11392 KB |
Output is correct |
5 |
Correct |
7 ms |
11392 KB |
Output is correct |
6 |
Correct |
7 ms |
11392 KB |
Output is correct |
7 |
Correct |
8 ms |
11392 KB |
Output is correct |
8 |
Incorrect |
7 ms |
11392 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
11392 KB |
Output is correct |
2 |
Correct |
7 ms |
11392 KB |
Output is correct |
3 |
Correct |
7 ms |
11392 KB |
Output is correct |
4 |
Correct |
7 ms |
11392 KB |
Output is correct |
5 |
Correct |
7 ms |
11392 KB |
Output is correct |
6 |
Correct |
7 ms |
11392 KB |
Output is correct |
7 |
Correct |
8 ms |
11392 KB |
Output is correct |
8 |
Incorrect |
7 ms |
11392 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
123 ms |
28172 KB |
Output is correct |
2 |
Correct |
122 ms |
28016 KB |
Output is correct |
3 |
Correct |
138 ms |
27256 KB |
Output is correct |
4 |
Correct |
147 ms |
28276 KB |
Output is correct |
5 |
Correct |
125 ms |
24692 KB |
Output is correct |
6 |
Correct |
149 ms |
27124 KB |
Output is correct |
7 |
Correct |
129 ms |
24824 KB |
Output is correct |
8 |
Correct |
142 ms |
25848 KB |
Output is correct |
9 |
Correct |
135 ms |
23928 KB |
Output is correct |
10 |
Correct |
141 ms |
24204 KB |
Output is correct |
11 |
Correct |
115 ms |
22392 KB |
Output is correct |
12 |
Correct |
111 ms |
22264 KB |
Output is correct |
13 |
Correct |
98 ms |
22520 KB |
Output is correct |
14 |
Correct |
102 ms |
22264 KB |
Output is correct |
15 |
Correct |
84 ms |
22008 KB |
Output is correct |
16 |
Correct |
111 ms |
21624 KB |
Output is correct |
17 |
Correct |
14 ms |
16128 KB |
Output is correct |
18 |
Correct |
14 ms |
16256 KB |
Output is correct |
19 |
Correct |
14 ms |
16000 KB |
Output is correct |
20 |
Correct |
15 ms |
15956 KB |
Output is correct |
21 |
Correct |
13 ms |
15872 KB |
Output is correct |
22 |
Correct |
17 ms |
15872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
11496 KB |
Output is correct |
2 |
Correct |
9 ms |
11520 KB |
Output is correct |
3 |
Correct |
10 ms |
11520 KB |
Output is correct |
4 |
Correct |
8 ms |
11520 KB |
Output is correct |
5 |
Correct |
8 ms |
11520 KB |
Output is correct |
6 |
Correct |
9 ms |
11520 KB |
Output is correct |
7 |
Correct |
10 ms |
11520 KB |
Output is correct |
8 |
Correct |
9 ms |
11520 KB |
Output is correct |
9 |
Correct |
11 ms |
11520 KB |
Output is correct |
10 |
Correct |
8 ms |
11520 KB |
Output is correct |
11 |
Correct |
8 ms |
11520 KB |
Output is correct |
12 |
Correct |
8 ms |
11520 KB |
Output is correct |
13 |
Correct |
8 ms |
11520 KB |
Output is correct |
14 |
Correct |
9 ms |
11520 KB |
Output is correct |
15 |
Correct |
8 ms |
11520 KB |
Output is correct |
16 |
Correct |
8 ms |
11520 KB |
Output is correct |
17 |
Correct |
14 ms |
11520 KB |
Output is correct |
18 |
Correct |
10 ms |
11520 KB |
Output is correct |
19 |
Correct |
14 ms |
11520 KB |
Output is correct |
20 |
Correct |
8 ms |
11520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
143 ms |
26360 KB |
Output is correct |
2 |
Correct |
138 ms |
26360 KB |
Output is correct |
3 |
Correct |
208 ms |
26360 KB |
Output is correct |
4 |
Correct |
144 ms |
26360 KB |
Output is correct |
5 |
Correct |
143 ms |
26360 KB |
Output is correct |
6 |
Correct |
152 ms |
33144 KB |
Output is correct |
7 |
Correct |
202 ms |
29556 KB |
Output is correct |
8 |
Correct |
164 ms |
28664 KB |
Output is correct |
9 |
Correct |
162 ms |
27728 KB |
Output is correct |
10 |
Correct |
141 ms |
26344 KB |
Output is correct |
11 |
Correct |
134 ms |
26360 KB |
Output is correct |
12 |
Correct |
123 ms |
26360 KB |
Output is correct |
13 |
Correct |
144 ms |
26360 KB |
Output is correct |
14 |
Correct |
139 ms |
25720 KB |
Output is correct |
15 |
Correct |
123 ms |
25080 KB |
Output is correct |
16 |
Correct |
72 ms |
22648 KB |
Output is correct |
17 |
Correct |
80 ms |
25192 KB |
Output is correct |
18 |
Correct |
89 ms |
25228 KB |
Output is correct |
19 |
Correct |
100 ms |
25568 KB |
Output is correct |
20 |
Correct |
95 ms |
25192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
11512 KB |
Output is correct |
2 |
Correct |
8 ms |
11520 KB |
Output is correct |
3 |
Correct |
8 ms |
11520 KB |
Output is correct |
4 |
Correct |
26 ms |
11392 KB |
Output is correct |
5 |
Correct |
8 ms |
11392 KB |
Output is correct |
6 |
Correct |
16 ms |
11392 KB |
Output is correct |
7 |
Correct |
9 ms |
11392 KB |
Output is correct |
8 |
Correct |
8 ms |
11392 KB |
Output is correct |
9 |
Correct |
9 ms |
11392 KB |
Output is correct |
10 |
Correct |
9 ms |
11392 KB |
Output is correct |
11 |
Correct |
9 ms |
11392 KB |
Output is correct |
12 |
Correct |
9 ms |
11520 KB |
Output is correct |
13 |
Correct |
8 ms |
11520 KB |
Output is correct |
14 |
Correct |
8 ms |
11520 KB |
Output is correct |
15 |
Correct |
9 ms |
11520 KB |
Output is correct |
16 |
Correct |
12 ms |
11392 KB |
Output is correct |
17 |
Correct |
16 ms |
11520 KB |
Output is correct |
18 |
Correct |
9 ms |
11392 KB |
Output is correct |
19 |
Correct |
21 ms |
11392 KB |
Output is correct |
20 |
Correct |
8 ms |
11392 KB |
Output is correct |
21 |
Correct |
8 ms |
11520 KB |
Output is correct |
22 |
Correct |
10 ms |
11520 KB |
Output is correct |
23 |
Correct |
15 ms |
11520 KB |
Output is correct |
24 |
Correct |
10 ms |
11520 KB |
Output is correct |
25 |
Correct |
8 ms |
11424 KB |
Output is correct |
26 |
Correct |
8 ms |
11392 KB |
Output is correct |
27 |
Correct |
8 ms |
11392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
26360 KB |
Output is correct |
2 |
Correct |
157 ms |
26104 KB |
Output is correct |
3 |
Correct |
166 ms |
24680 KB |
Output is correct |
4 |
Correct |
159 ms |
23100 KB |
Output is correct |
5 |
Correct |
141 ms |
21624 KB |
Output is correct |
6 |
Correct |
133 ms |
21088 KB |
Output is correct |
7 |
Correct |
121 ms |
20676 KB |
Output is correct |
8 |
Correct |
109 ms |
20344 KB |
Output is correct |
9 |
Correct |
121 ms |
20216 KB |
Output is correct |
10 |
Correct |
122 ms |
20088 KB |
Output is correct |
11 |
Correct |
117 ms |
19960 KB |
Output is correct |
12 |
Correct |
123 ms |
19832 KB |
Output is correct |
13 |
Correct |
116 ms |
19576 KB |
Output is correct |
14 |
Correct |
116 ms |
20980 KB |
Output is correct |
15 |
Correct |
200 ms |
28404 KB |
Output is correct |
16 |
Correct |
207 ms |
27256 KB |
Output is correct |
17 |
Correct |
167 ms |
27252 KB |
Output is correct |
18 |
Correct |
160 ms |
26232 KB |
Output is correct |
19 |
Correct |
155 ms |
23164 KB |
Output is correct |
20 |
Correct |
157 ms |
23104 KB |
Output is correct |
21 |
Correct |
160 ms |
23160 KB |
Output is correct |
22 |
Correct |
142 ms |
22512 KB |
Output is correct |
23 |
Correct |
121 ms |
21696 KB |
Output is correct |
24 |
Correct |
148 ms |
24696 KB |
Output is correct |
25 |
Correct |
149 ms |
24948 KB |
Output is correct |
26 |
Correct |
206 ms |
23792 KB |
Output is correct |
27 |
Correct |
144 ms |
23800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
11392 KB |
Output is correct |
2 |
Correct |
7 ms |
11392 KB |
Output is correct |
3 |
Correct |
7 ms |
11392 KB |
Output is correct |
4 |
Correct |
7 ms |
11392 KB |
Output is correct |
5 |
Correct |
7 ms |
11392 KB |
Output is correct |
6 |
Correct |
7 ms |
11392 KB |
Output is correct |
7 |
Correct |
8 ms |
11392 KB |
Output is correct |
8 |
Incorrect |
7 ms |
11392 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
11392 KB |
Output is correct |
2 |
Correct |
7 ms |
11392 KB |
Output is correct |
3 |
Correct |
7 ms |
11392 KB |
Output is correct |
4 |
Correct |
7 ms |
11392 KB |
Output is correct |
5 |
Correct |
7 ms |
11392 KB |
Output is correct |
6 |
Correct |
7 ms |
11392 KB |
Output is correct |
7 |
Correct |
8 ms |
11392 KB |
Output is correct |
8 |
Incorrect |
7 ms |
11392 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |