#include<bits/stdc++.h>
#define lf double
#define ll long long
#define ull unsigned ll
#define ii pair<int,int>
#define li pair<ll,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define iiii2 pair<int,iii>
#define lii pair<ll,ii>
#define lolo pair<ll,ll>
#define heap priority_queue
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) x.begin(),x.end()
#define len(x) strlen(x)
#define sz(x) (int) x.size()
#define orta ((bas+son)/2)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)
#define umin(x,y) x=min(x,y)
#define umax(x,y) x=max(x,y)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define MOD 1000000007
#define inf 1000000000
#define N 100005
#define LOG 20
#define magic 100
#define KOK 350
#define EPS 0.0025
#define pw(x) ((1ll)<<(x))
#define PI 3.1415926535
#define get(x,y) ((x<0)?(x+y):(x))
using namespace std;
int n,m,x,y,bcc,t,sz;
int sub[N],vis[N],low[N];
vector<int> Nodes[N],Gr[N],v[N];
ll ans;
stack<int> S;
void dfs(int B,int ata) {
sub[B]=sz(Nodes[B]);
for(int node:Nodes[B]) {
for(int G:Gr[node]) {
if(G==B || G==ata) continue ;
dfs(G,B);
sub[B]+=sub[G]-1;
ans-=1ll*sub[G]*(sub[G]-1)*(sz(Nodes[B])-1);
}
}
if(ata!=-1) ans-=1ll*(sz-sub[B]+1)*(sz-sub[B])*(sz(Nodes[B])-1);
}
void found(int x,int node) {
for(int temp=0;temp!=x;) {
temp=S.top();
S.pop();
Nodes[bcc].pb(temp);
Gr[temp].pb(bcc);
}
Nodes[bcc].pb(node);
Gr[node].pb(bcc);
}
void bccF(int node,int ata) {
vis[node]=low[node]=++t;
sz++;
for(int i:v[node]) {
if(i==ata) continue ;
if(!vis[i]) {
S.push(i);
bccF(i,node);
if(low[i]>=vis[node]) {
bcc++;
found(i,node);
}
}
else {
umin(low[node],vis[i]);
}
}
}
int main() {
#if 0
freopen("input.txt","r",stdin);
#endif
scanf("%d %d",&n,&m);
for(int i=1;i<=m;i++) {
scanf("%d %d",&x,&y);
v[x].pb(y);
v[y].pb(x);
}
for(int i=1;i<=n;i++) {
if(!vis[i]) {
sz=0;
S.push(i);
bccF(i,-1);
S.pop();
ans+=1ll*sz*(sz-1)*(sz-2);
dfs(Gr[i][0],-1);
}
}
printf("%lld",ans);
}
Compilation message
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:133: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:137:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&x,&y);
~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
15 ms |
14584 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
15 ms |
14584 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
172 ms |
34604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1108 ms |
898464 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1133 ms |
908476 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1130 ms |
1120848 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1116 ms |
1120848 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
15 ms |
14584 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
15 ms |
14584 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |