#include<bits/stdc++.h>
#define fi first
#define pb push_back
#define ll long long
using namespace std;
int n,m;
ll re=0;
int szz=0;
const int N=200009;
vector<pair<int,int>>v[N];
vector<int>v1[N];
ll cnt=1,num[N],low[N],bridge[N],b[N],par[N],vis[N],sz[N],bo[N],t[N];
void solve(int x,int p)
{
vis[x]=1;
for(auto it:v1[x])
{
if(it==p)continue;
solve(it,x);
sz[x]+=sz[it];
}
sz[x]+=1;bo[x]=1;
}
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+=2*up*bo[x]*sz[x];
/*if(bo[x]>2)
{
re+=(up)*((bo[x])-1)*((bo[x])-2)*2;
re+=(sz[x])*(bo[x]-1)*(bo[x]-2)*2;
}
re+=(bo[x]-1)*up*2;
re+=(bo[x]-1)*(sz[x])*2;*/
for(auto it:v1[x])
{
if(it==p)continue;
re+=2*t[x]*sz[it];
t[x]+=sz[it];
go(it,x,up+bo[x]+sz[x]-sz[it]);
}
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
scanf("%d %d", &n, &m);
for(int i=0;i<m;i++)
{
int x,y;cin>>x>>y;
v1[x].pb(y);
v1[y].pb(x);
}
cnt=n+1;
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:50:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
23 ms |
19456 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
23 ms |
19456 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
124 ms |
17016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
11392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
89 ms |
17024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
11392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
90 ms |
17016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
23 ms |
19456 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
23 ms |
19456 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |