#include <bits/stdc++.h>
using namespace std;
int n,m,cut[100001],dfn[100001],low[100001],o,dn;
int bsz[200001];
vector<int> adj[100001],badj[200001];
stack<int> stk;
int ts;
void addEdge(int u,int v) {
badj[u].push_back(v);
badj[v].push_back(u);
}
void dfs(int cur,int p,int root=0) {
ts++;
dfn[cur] = low[cur] = ++dn;
stk.push(cur);
int c=0;
for(auto &it:adj[cur]) if(it!=p) {
if(dfn[it]) low[cur] = min(low[cur],low[it]);
else {
dfs(it,cur);
low[cur] = min(low[cur],low[it]);
if(low[it]>=dfn[cur]) {
if(root && !c) {
c=1; continue;
}
++n;
cut[cur] = 1;
while(!stk.empty()) {
int v=stk.top();
bsz[n]++;
if(cut[v]) addEdge(n, v);
if(v==cur) break;
stk.pop();
}
}
}
}
if(root && c>1) {
++n;
cut[cur] = 1;
while(!stk.empty()) {
int v=stk.top();
bsz[n]++;
if(cut[v]) addEdge(n, v);
if(v==cur) break;
stk.pop();
}
}
}
long long ans;
int sz[200001];
int cal_dfs(int cur,int p) {
sz[cur] = bsz[cur];
for(auto &it:badj[cur]) if(it!=p) sz[cur] += cal_dfs(it,cur);
sz[cur] -= ((int)badj[cur].size() - (p>0) - (cur<=o));
if(cur>o) {
for(auto &it:badj[cur]) if(it!=p) ans += 1ll*(bsz[cur]-1)*sz[it]*(sz[it]-1);
ans += 1ll*(bsz[cur]-1)*(ts-sz[cur]+1)*(ts-sz[cur]);
}
return sz[cur];
}
int main() {
scanf("%d%d",&n,&m);
for(int i=0,u,v;i<m;i++) {
scanf("%d%d",&u,&v);
adj[u].push_back(v);
adj[v].push_back(u);
}
o = n;
long long ret = 0;
for(int i=1;i<=o;i++) if(!dfn[i]) {
ts=0; ans=0;
dfs(i,0,1);
while(!stk.empty()) stk.pop();
cal_dfs(i, 0);
ret += 1ll*ts*(ts-1)*(ts-2) - ans;
}
printf("%lld\n",ret);
return 0;
}
Compilation message
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:69:10: 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:71:14: 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 |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
8 ms |
7416 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
8 ms |
7416 KB |
Output is correct |
5 |
Correct |
8 ms |
7416 KB |
Output is correct |
6 |
Correct |
8 ms |
7416 KB |
Output is correct |
7 |
Incorrect |
8 ms |
7544 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
8 ms |
7416 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
8 ms |
7416 KB |
Output is correct |
5 |
Correct |
8 ms |
7416 KB |
Output is correct |
6 |
Correct |
8 ms |
7416 KB |
Output is correct |
7 |
Incorrect |
8 ms |
7544 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
21248 KB |
Output is correct |
2 |
Correct |
101 ms |
21136 KB |
Output is correct |
3 |
Incorrect |
127 ms |
22356 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
7544 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
130 ms |
17824 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
7544 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
118 ms |
17060 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
8 ms |
7416 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
8 ms |
7416 KB |
Output is correct |
5 |
Correct |
8 ms |
7416 KB |
Output is correct |
6 |
Correct |
8 ms |
7416 KB |
Output is correct |
7 |
Incorrect |
8 ms |
7544 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
8 ms |
7416 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
8 ms |
7416 KB |
Output is correct |
5 |
Correct |
8 ms |
7416 KB |
Output is correct |
6 |
Correct |
8 ms |
7416 KB |
Output is correct |
7 |
Incorrect |
8 ms |
7544 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |