#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;
const int MAXN = 100010;
vector<int> adj[MAXN];
int dep[MAXN];
int lo[MAXN];
int id[MAXN];
vector<int> bcc[MAXN * 2];
int siz[MAXN * 2];
int sum[MAXN * 2];
int ban[MAXN * 2];
int cur_bcc;
vector<int> st;
void dfs_bcc(int n, int p, int d) {
dep[n] = lo[n] = d;
st.eb(n);
for(auto &i:adj[n]) if(i != p) {
if(dep[i]) {
lo[n] = min(lo[n], dep[i]);
} else {
dfs_bcc(i, n, d + 1);
lo[n] = min(lo[n], lo[i]);
if(lo[i] >= dep[n]) {
// bcc found
cur_bcc++;
int last = 0;
while(last != n) {
last = st.back(); st.pop_back();
bcc[last].eb(cur_bcc);
bcc[cur_bcc].eb(last);
}
st.eb(n);
}
}
}
}
void dfs_siz(int n, int p, int N, int d) {
dep[n] = d;
sum[n] = siz[n] = (n <= N);
for(auto &i:bcc[n]) if(i != p) {
dfs_siz(i, n, N, d + 1);
sum[n] += sum[i];
}
}
#define C(x) ((x) * ((x) - 1))
void dfs_ban(int n, int p, int N, int tot) {
auto size = [&](int r, int k) {
if(dep[k] < dep[r]) return tot - sum[r];
return sum[k];
};
for(auto &i:bcc[n]) if(i != p) {
dfs_ban(i, n, N, tot);
}
if(n > N) {
for(auto &i:bcc[n]) {
// cout << n << " " << i << " " << size(n, i) << " " << tot - sum[n] << " " << sum[i] << "\n";
ban[n] += C(size(n, i));
ban[i] -= C(size(n, i));
}
for(auto &i:bcc[n]) {
ban[i] += ban[n];
}
}
}
int ans = 0;
void dfs_ans(int n, int p, int N, int tot) {
if(n <= N) ans += C(tot - 1) - ban[n];
for(auto &i:bcc[n]) if(i != p) dfs_ans(i, n, N, tot);
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
// =^-w-^= nya
int n, m; cin >> n >> m;
while(m--) {
int a, b; cin >> a >> b;
adj[a].eb(b);
adj[b].eb(a);
}
cur_bcc = n;
For(i, 1, n) if(!dep[i]) {
dfs_bcc(i, i, 1);
dfs_siz(i, i, n, 1);
// cout << i << " " << sum[i] << "\n";
dfs_ban(i, i, n, sum[i]);
dfs_ans(i, i, n, sum[i]);
}
cout << ans << "\n";
// For(i, 1, cur_bcc) cout << dep[i] << " \n"[i == cur_bcc];
// For(i, 1, cur_bcc) cout << ban[i] << " \n"[i == cur_bcc];
// For(i, 1, cur_bcc) {
// cout << i << ":";
// for(auto &j:bcc[i]) cout << " " << j;
// cout << "\n";
// }
return 0;
}
/*
4 3
1 2
2 3
3 4
= 8
4 4
1 2
2 3
3 4
4 2
= 14
5 5
1 2
2 3
3 1
3 4
3 5
= 24
5 6
1 2
2 3
3 1
1 4
4 5
5 1
= 36
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
5 ms |
7384 KB |
Output is correct |
5 |
Correct |
5 ms |
7380 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Incorrect |
5 ms |
7376 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
5 ms |
7384 KB |
Output is correct |
5 |
Correct |
5 ms |
7380 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Incorrect |
5 ms |
7376 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
29740 KB |
Output is correct |
2 |
Correct |
90 ms |
29976 KB |
Output is correct |
3 |
Runtime error |
128 ms |
55188 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7508 KB |
Output is correct |
2 |
Correct |
5 ms |
7520 KB |
Output is correct |
3 |
Correct |
4 ms |
7508 KB |
Output is correct |
4 |
Correct |
5 ms |
7636 KB |
Output is correct |
5 |
Correct |
4 ms |
7636 KB |
Output is correct |
6 |
Correct |
5 ms |
7636 KB |
Output is correct |
7 |
Correct |
4 ms |
7644 KB |
Output is correct |
8 |
Correct |
4 ms |
7636 KB |
Output is correct |
9 |
Correct |
5 ms |
7508 KB |
Output is correct |
10 |
Correct |
5 ms |
7508 KB |
Output is correct |
11 |
Correct |
4 ms |
7508 KB |
Output is correct |
12 |
Correct |
4 ms |
7508 KB |
Output is correct |
13 |
Correct |
5 ms |
7508 KB |
Output is correct |
14 |
Correct |
5 ms |
7508 KB |
Output is correct |
15 |
Correct |
5 ms |
7508 KB |
Output is correct |
16 |
Correct |
6 ms |
7508 KB |
Output is correct |
17 |
Correct |
4 ms |
7512 KB |
Output is correct |
18 |
Correct |
4 ms |
7512 KB |
Output is correct |
19 |
Correct |
5 ms |
7508 KB |
Output is correct |
20 |
Correct |
5 ms |
7520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
123 ms |
50224 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7508 KB |
Output is correct |
2 |
Correct |
5 ms |
7508 KB |
Output is correct |
3 |
Incorrect |
4 ms |
7508 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
134 ms |
50172 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
5 ms |
7384 KB |
Output is correct |
5 |
Correct |
5 ms |
7380 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Incorrect |
5 ms |
7376 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
5 ms |
7384 KB |
Output is correct |
5 |
Correct |
5 ms |
7380 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Incorrect |
5 ms |
7376 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |