#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 2;
ll ans = 0;
int num[N + 2], low[N + 2], timer , n , m , scc;
stack < int > st;
vector < int > adj[N + 2] , g[N + 2];
ll sz[N + 2];
void dfs(int u , int p = - 1){
low[u] = num[u] = ++timer;
st.push(u);
for(auto v: adj[u]){
if(v == p)continue;
if(!num[v]){
dfs(v , u);
low[u] = min(low[u] , low[v]);
if(low[v] >= num[u]){
scc ++;
g[scc].push_back(u);
g[u].push_back(scc);
int y;
do{
y = st.top();
st.pop();
g[y].push_back(scc);
g[scc].push_back(y);
}while(y != v);
}
}
else{
low[u] = min(low[u] , num[v]);
}
}
}
ll cal(ll total_square , ll total , ll er){
total_square -= er * er;
total -= er;
return total * total - total_square;
}
ll three_im(ll x , ll z){
if(x < z)return 0;
ll k = 1;
for(ll i = x ;i >= x - z + 1; i --){
k *= i;
}
return k ;
}
void dfs2(int u , int p = - 1){
if(u <= n)sz[u] ++;
for(auto v: g[u]){
if(v == p)continue;
dfs2(v , u);
sz[u] += sz[v];
}
if(u > n){
ans += three_im(g[u].size() - 1, 2) * (n - sz[u] - 1);
return ;
}
ll oth = n - sz[u] ;
ll total_square = 0;
ll total = 0;
for(auto v: g[u]){
if(v == p) continue;
total_square += sz[v] * sz[v];
total += sz[v];
}
total_square += oth * oth;
total += oth;
ans += cal(total_square , total , 0) * 2;
for(auto v: g[u]){
if(v == p)continue;
ans += cal(total_square , total , sz[v]);
}
ans += cal(total_square , total , oth);
}
void solve() {
cin >> n >> m;
scc = n;
for(int i = 1; i <= m ; i ++){
int u , v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1);
dfs2(1);
cout << three_im(n , 3) - ans;
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
#define _ "minrect."
if (fopen(_ "inp", "r")) {
freopen(_ "inp", "r", stdin);
freopen(_ "out", "w", stdout);
}
solve();
}
Compilation message
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:97:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
97 | freopen(_ "inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
count_triplets.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
98 | freopen(_ "out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
12632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
12632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
31944 KB |
Output is correct |
2 |
Correct |
41 ms |
31956 KB |
Output is correct |
3 |
Incorrect |
30 ms |
23912 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
12888 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
37 ms |
22364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
12888 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
48 ms |
22324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
12632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
12632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |