#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int nax = 2e5;
vector<int> g[nax];
int seg[4*nax],lazy[4*nax],fr[nax],to[nax],id[nax];
int T,n,m;
ll ans;
void pro(int n,int s,int e){
seg[n] += lazy[n]*(e-s+1);
if(s != e){
lazy[n*2] += lazy[n];
lazy[n*2+1] += lazy[n];
}
lazy[n] = 0;
}
void update(int n,int s,int e,int l,int r,int val){
pro(n,s,e);
if(s > r || e < l)
return;
if(s >= l && e <= r){
lazy[n] += val;
pro(n,s,e);
return;
}
update(n*2,s,(s+e)/2,l,r,val);
update(n*2+1,(s+e)/2+1,e,l,r,val);
seg[n] = seg[n*2] + seg[n*2+1];
}
void dfs(int u,int p,int d){
id[u] = fr[u] = ++T;
update(1,1,n,T,T,d);
for(int v : g[u]){
if(v == p)
continue;
dfs(v,u,d+1);
}
to[u] = T;
}
void calc(int u,int p){
ans += seg[1] - n + 1;
for(int v : g[u]){
if(v == p)
continue;
update(1,1,n,1,n,1);
update(1,1,n,fr[v],to[v],-2);
calc(v,u);
update(1,1,n,1,n,-1);
update(1,1,n,fr[v],to[v],2);
}
}
const int kax = 100;
bool can[kax],vis[kax];
int count(int u,int t){
if(u == t)return 1;
vis[u] = 1;
for(int v : g[u]){
if(vis[v])continue;
// cout << v << ' ' << u << endl;
can[u] |= count(v,t);
}
vis[u] = 0;
return can[u];
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++){
int u,v;
scanf("%d%d",&u,&v);
g[u].push_back(v);
g[v].push_back(u);
}
if(n == m && n > 10){
ans = n * 1ll * (n-1) * (n-2);
}else if(n <= 50){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i == j)continue;
memset(can,0,sizeof(can));
// cout << i << ' ' << j << endl;
count(i,j);
// cout << i << ' ' << j << endl;
for(int x=1;x<=n;x++){
if(x == i || x == j)continue;
// if(can[x])cout << i << ' ' << x << ' ' << j << endl;
ans += can[x];
}
}
}
}else{
dfs(1,0,0);
calc(1,0);
}
printf("%lld\n", ans);
}
Compilation message
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:86:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen("input.txt","r",stdin);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
count_triplets.cpp:88:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
~~~~~^~~~~~~~~~~~~~
count_triplets.cpp:91:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&u,&v);
~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
4992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
4992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
4992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
4992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
4992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
4992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
4992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
4992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
4992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |