This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
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];
}
ll get(int n,int s,int e,int l,int r){
pro(n,s,e);
if(s > r || e < l)
return 0;
if(s >= l && e <= r)
return seg[n];
return get(n*2,s,(s+e)/2,l,r) + get(n*2+1,(s+e)/2+1,e,l,r);
}
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 += get(1,1,n,1,n) - 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 > 50){
ans = n * (n-1) * (n-2);
}/*else if(n == m+1){
dfs(1,0,0);
calc(1,0);
}*/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;
// cout << i << ' ' << j << ' ' << x << endl;
ans += can[x];
}
}
}
}else assert(0);
printf("%lld\n", ans);
}
Compilation message (stderr)
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:94: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:96: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:99:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&u,&v);
~~~~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |