#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];
vector<int> bcc[MAXN];
int par[MAXN];
int dep[MAXN];
int id[MAXN];
int siz[MAXN];
int sum[MAXN];
int cur_bcc = 0;
void dfs_bcc(int n, int p, int d) {
par[n] = p;
dep[n] = d;
for(auto &i:adj[n]) if(i != p) {
if(!par[i]) {
// tree edge
dfs_bcc(i, n, d + 1);
} else if(dep[i] < dep[n]) {
// back edge
cur_bcc++;
int t = n;
while(true) {
id[t] = cur_bcc;
if(t == i) break;
t = par[t];
}
}
}
if(!id[n]) id[n] = ++cur_bcc;
for(auto &i:adj[n]) if(dep[i] > dep[n] && id[i] != id[n]) {
bcc[id[i]].eb(id[n]);
bcc[id[n]].eb(id[i]);
}
siz[id[n]]++;
}
void dfs_siz(int n, int p) {
sum[n] = siz[n];
assert(siz[n] == 1);
for(auto &i:bcc[n]) if(i != p) {
// assert(!siz[i]);
dfs_siz(i, n);
sum[n] += sum[i];
}
}
int ans;
#define C(x) ((x) * ((x) - 1))
void dfs_ans(int n, int p, int tot_n) {
int t = C(tot_n - 1) * siz[n];
for(auto &i:bcc[n]) {
int s = sum[i];
if(i == p) s = tot_n - sum[n];
t -= C(s + 1) * (siz[n] - 1) + C(s);
if(i != p) dfs_ans(i, n, tot_n);
}
ans += t;
}
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);
}
ans = 0;
For(i, 1, n) if(!par[i]) {
For(j, 1, cur_bcc) {
bcc[j].clear();
siz[j] = 0;
}
cur_bcc = 0;
dfs_bcc(i, i, 1);
dfs_siz(1, 1);
dfs_ans(1, 1, sum[1]);
// cout << cur_bcc << "\n";
// For(j, 1, cur_bcc) {
// cout << j << " = " << siz[j] << ", " << sum[j] << ":";
// for(auto &k:bcc[j]) cout << " " << k;
// cout << "\n";
// }
// cout << flush;
}
cout << ans << "\n";
return 0;
}
/*
4 3
1 2
2 3
3 4
4 4
1 2
2 3
3 4
4 2
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
9940 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
9940 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
71 ms |
40056 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
4 ms |
5204 KB |
Output is correct |
5 |
Correct |
5 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5204 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5164 KB |
Output is correct |
12 |
Correct |
3 ms |
5076 KB |
Output is correct |
13 |
Correct |
3 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
5076 KB |
Output is correct |
16 |
Correct |
3 ms |
5032 KB |
Output is correct |
17 |
Correct |
3 ms |
5076 KB |
Output is correct |
18 |
Correct |
3 ms |
5152 KB |
Output is correct |
19 |
Correct |
3 ms |
5076 KB |
Output is correct |
20 |
Correct |
4 ms |
5168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
16396 KB |
Output is correct |
2 |
Correct |
61 ms |
16380 KB |
Output is correct |
3 |
Correct |
59 ms |
16324 KB |
Output is correct |
4 |
Correct |
67 ms |
16304 KB |
Output is correct |
5 |
Correct |
87 ms |
16316 KB |
Output is correct |
6 |
Correct |
83 ms |
23000 KB |
Output is correct |
7 |
Correct |
70 ms |
19304 KB |
Output is correct |
8 |
Correct |
74 ms |
18508 KB |
Output is correct |
9 |
Correct |
102 ms |
17688 KB |
Output is correct |
10 |
Correct |
62 ms |
14488 KB |
Output is correct |
11 |
Correct |
64 ms |
16732 KB |
Output is correct |
12 |
Correct |
61 ms |
13800 KB |
Output is correct |
13 |
Correct |
56 ms |
13492 KB |
Output is correct |
14 |
Correct |
46 ms |
11668 KB |
Output is correct |
15 |
Correct |
58 ms |
11528 KB |
Output is correct |
16 |
Correct |
33 ms |
10400 KB |
Output is correct |
17 |
Correct |
40 ms |
17432 KB |
Output is correct |
18 |
Correct |
43 ms |
17508 KB |
Output is correct |
19 |
Correct |
43 ms |
17748 KB |
Output is correct |
20 |
Correct |
42 ms |
17492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Runtime error |
7 ms |
10180 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
16404 KB |
Output is correct |
2 |
Correct |
61 ms |
16112 KB |
Output is correct |
3 |
Runtime error |
76 ms |
28452 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
9940 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
9940 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |