#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
int n, m, N;
vector<int> graph[100001], bcc_graph[200001], stck;
int low[100001], tin[100001], timer = 1, bccs = 1, aps[100001];
ll ans;
void dfs(int node, int parent = 0) {
low[node] = tin[node] = timer++;
N++;
stck.push_back(node);
for (int i : graph[node]) if (i != parent) {
if (tin[i]) low[node] = min(low[node], tin[i]);
else {
dfs(i, node);
low[node] = min(low[node], low[i]);
if (low[i] >= tin[node]) {
bcc_graph[node].push_back(n + bccs);
while (!bcc_graph[n + bccs].size() || bcc_graph[n + bccs].back() != i) {
bcc_graph[n + bccs].push_back(stck.back());
stck.pop_back();
}
bccs++;
}
}
}
}
void dfs2(int node, int parent = 0) {
aps[node] = (node <= n);
for (int i : bcc_graph[node]) {
dfs2(i, node);
aps[node] += aps[i];
if (node > n) ans -= (bcc_graph[node].size() - (parent == 0)) * aps[i] * (aps[i] - 1);
}
if (node > n) ans -= bcc_graph[node].size() * (N - aps[node]) * (N - aps[node] - 1);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
while (m--) {
int u, v;
cin >> u >> v;
graph[u].push_back(v);
graph[v].push_back(u);
}
FOR(i, 1, n + 1) if (!tin[i]) {
N = 0;
dfs(i);
ans += N * (N - 1) * (N - 2);
dfs2(i);
}
// FOR(i, 1, n + bccs) {
// cout << i << ": ";
// for (int j : bcc_graph[i]) cout << j << ' ';
// cout << '\n';
// }
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7424 KB |
Output is correct |
2 |
Correct |
4 ms |
7424 KB |
Output is correct |
3 |
Correct |
5 ms |
7424 KB |
Output is correct |
4 |
Correct |
5 ms |
7424 KB |
Output is correct |
5 |
Correct |
5 ms |
7348 KB |
Output is correct |
6 |
Correct |
4 ms |
7424 KB |
Output is correct |
7 |
Correct |
6 ms |
7424 KB |
Output is correct |
8 |
Correct |
5 ms |
7424 KB |
Output is correct |
9 |
Correct |
6 ms |
7424 KB |
Output is correct |
10 |
Correct |
5 ms |
7424 KB |
Output is correct |
11 |
Correct |
4 ms |
7424 KB |
Output is correct |
12 |
Correct |
6 ms |
7424 KB |
Output is correct |
13 |
Correct |
5 ms |
7424 KB |
Output is correct |
14 |
Correct |
6 ms |
7424 KB |
Output is correct |
15 |
Correct |
6 ms |
7424 KB |
Output is correct |
16 |
Correct |
6 ms |
7424 KB |
Output is correct |
17 |
Correct |
6 ms |
7424 KB |
Output is correct |
18 |
Correct |
6 ms |
7424 KB |
Output is correct |
19 |
Correct |
5 ms |
7424 KB |
Output is correct |
20 |
Correct |
6 ms |
7424 KB |
Output is correct |
21 |
Correct |
6 ms |
7424 KB |
Output is correct |
22 |
Correct |
6 ms |
7424 KB |
Output is correct |
23 |
Correct |
6 ms |
7424 KB |
Output is correct |
24 |
Correct |
6 ms |
7424 KB |
Output is correct |
25 |
Correct |
6 ms |
7424 KB |
Output is correct |
26 |
Correct |
4 ms |
7424 KB |
Output is correct |
27 |
Correct |
5 ms |
7424 KB |
Output is correct |
28 |
Correct |
6 ms |
7424 KB |
Output is correct |
29 |
Correct |
5 ms |
7424 KB |
Output is correct |
30 |
Correct |
4 ms |
7424 KB |
Output is correct |
31 |
Correct |
4 ms |
7424 KB |
Output is correct |
32 |
Correct |
6 ms |
7424 KB |
Output is correct |
33 |
Correct |
6 ms |
7424 KB |
Output is correct |
34 |
Correct |
5 ms |
7424 KB |
Output is correct |
35 |
Correct |
4 ms |
7424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7424 KB |
Output is correct |
2 |
Correct |
4 ms |
7424 KB |
Output is correct |
3 |
Correct |
5 ms |
7424 KB |
Output is correct |
4 |
Correct |
5 ms |
7424 KB |
Output is correct |
5 |
Correct |
5 ms |
7348 KB |
Output is correct |
6 |
Correct |
4 ms |
7424 KB |
Output is correct |
7 |
Correct |
6 ms |
7424 KB |
Output is correct |
8 |
Correct |
5 ms |
7424 KB |
Output is correct |
9 |
Correct |
6 ms |
7424 KB |
Output is correct |
10 |
Correct |
5 ms |
7424 KB |
Output is correct |
11 |
Correct |
4 ms |
7424 KB |
Output is correct |
12 |
Correct |
6 ms |
7424 KB |
Output is correct |
13 |
Correct |
5 ms |
7424 KB |
Output is correct |
14 |
Correct |
6 ms |
7424 KB |
Output is correct |
15 |
Correct |
6 ms |
7424 KB |
Output is correct |
16 |
Correct |
6 ms |
7424 KB |
Output is correct |
17 |
Correct |
6 ms |
7424 KB |
Output is correct |
18 |
Correct |
6 ms |
7424 KB |
Output is correct |
19 |
Correct |
5 ms |
7424 KB |
Output is correct |
20 |
Correct |
6 ms |
7424 KB |
Output is correct |
21 |
Correct |
6 ms |
7424 KB |
Output is correct |
22 |
Correct |
6 ms |
7424 KB |
Output is correct |
23 |
Correct |
6 ms |
7424 KB |
Output is correct |
24 |
Correct |
6 ms |
7424 KB |
Output is correct |
25 |
Correct |
6 ms |
7424 KB |
Output is correct |
26 |
Correct |
4 ms |
7424 KB |
Output is correct |
27 |
Correct |
5 ms |
7424 KB |
Output is correct |
28 |
Correct |
6 ms |
7424 KB |
Output is correct |
29 |
Correct |
5 ms |
7424 KB |
Output is correct |
30 |
Correct |
4 ms |
7424 KB |
Output is correct |
31 |
Correct |
4 ms |
7424 KB |
Output is correct |
32 |
Correct |
6 ms |
7424 KB |
Output is correct |
33 |
Correct |
6 ms |
7424 KB |
Output is correct |
34 |
Correct |
5 ms |
7424 KB |
Output is correct |
35 |
Correct |
4 ms |
7424 KB |
Output is correct |
36 |
Correct |
5 ms |
7424 KB |
Output is correct |
37 |
Correct |
6 ms |
7424 KB |
Output is correct |
38 |
Correct |
6 ms |
7424 KB |
Output is correct |
39 |
Correct |
5 ms |
7424 KB |
Output is correct |
40 |
Correct |
6 ms |
7424 KB |
Output is correct |
41 |
Correct |
4 ms |
7424 KB |
Output is correct |
42 |
Correct |
5 ms |
7424 KB |
Output is correct |
43 |
Correct |
7 ms |
7424 KB |
Output is correct |
44 |
Correct |
6 ms |
7424 KB |
Output is correct |
45 |
Correct |
5 ms |
7424 KB |
Output is correct |
46 |
Correct |
7 ms |
7424 KB |
Output is correct |
47 |
Correct |
7 ms |
7424 KB |
Output is correct |
48 |
Correct |
7 ms |
7424 KB |
Output is correct |
49 |
Correct |
4 ms |
7424 KB |
Output is correct |
50 |
Correct |
4 ms |
7424 KB |
Output is correct |
51 |
Correct |
5 ms |
7424 KB |
Output is correct |
52 |
Correct |
4 ms |
7424 KB |
Output is correct |
53 |
Correct |
4 ms |
7424 KB |
Output is correct |
54 |
Correct |
5 ms |
7424 KB |
Output is correct |
55 |
Correct |
4 ms |
7424 KB |
Output is correct |
56 |
Correct |
5 ms |
7424 KB |
Output is correct |
57 |
Correct |
4 ms |
7424 KB |
Output is correct |
58 |
Correct |
4 ms |
7424 KB |
Output is correct |
59 |
Correct |
5 ms |
7424 KB |
Output is correct |
60 |
Correct |
5 ms |
7424 KB |
Output is correct |
61 |
Correct |
4 ms |
7424 KB |
Output is correct |
62 |
Correct |
4 ms |
7424 KB |
Output is correct |
63 |
Correct |
4 ms |
7424 KB |
Output is correct |
64 |
Correct |
4 ms |
7424 KB |
Output is correct |
65 |
Correct |
4 ms |
7424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
69 ms |
20592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
7552 KB |
Output is correct |
2 |
Correct |
4 ms |
7552 KB |
Output is correct |
3 |
Correct |
5 ms |
7552 KB |
Output is correct |
4 |
Correct |
5 ms |
7680 KB |
Output is correct |
5 |
Correct |
5 ms |
7552 KB |
Output is correct |
6 |
Correct |
6 ms |
7552 KB |
Output is correct |
7 |
Correct |
5 ms |
7552 KB |
Output is correct |
8 |
Correct |
5 ms |
7552 KB |
Output is correct |
9 |
Correct |
6 ms |
7552 KB |
Output is correct |
10 |
Correct |
5 ms |
7552 KB |
Output is correct |
11 |
Correct |
5 ms |
7552 KB |
Output is correct |
12 |
Correct |
7 ms |
7424 KB |
Output is correct |
13 |
Correct |
8 ms |
7552 KB |
Output is correct |
14 |
Correct |
5 ms |
7552 KB |
Output is correct |
15 |
Correct |
7 ms |
7424 KB |
Output is correct |
16 |
Correct |
5 ms |
7424 KB |
Output is correct |
17 |
Correct |
5 ms |
7424 KB |
Output is correct |
18 |
Correct |
5 ms |
7424 KB |
Output is correct |
19 |
Correct |
7 ms |
7424 KB |
Output is correct |
20 |
Correct |
7 ms |
7424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
109 ms |
16632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7552 KB |
Output is correct |
2 |
Correct |
5 ms |
7552 KB |
Output is correct |
3 |
Correct |
5 ms |
7424 KB |
Output is correct |
4 |
Correct |
5 ms |
7424 KB |
Output is correct |
5 |
Correct |
5 ms |
7424 KB |
Output is correct |
6 |
Correct |
5 ms |
7424 KB |
Output is correct |
7 |
Correct |
5 ms |
7424 KB |
Output is correct |
8 |
Correct |
5 ms |
7424 KB |
Output is correct |
9 |
Correct |
7 ms |
7424 KB |
Output is correct |
10 |
Correct |
6 ms |
7424 KB |
Output is correct |
11 |
Correct |
5 ms |
7424 KB |
Output is correct |
12 |
Correct |
6 ms |
7572 KB |
Output is correct |
13 |
Correct |
6 ms |
7552 KB |
Output is correct |
14 |
Correct |
6 ms |
7552 KB |
Output is correct |
15 |
Correct |
6 ms |
7552 KB |
Output is correct |
16 |
Correct |
5 ms |
7424 KB |
Output is correct |
17 |
Correct |
8 ms |
7540 KB |
Output is correct |
18 |
Correct |
6 ms |
7424 KB |
Output is correct |
19 |
Correct |
8 ms |
7424 KB |
Output is correct |
20 |
Correct |
6 ms |
7424 KB |
Output is correct |
21 |
Correct |
6 ms |
7424 KB |
Output is correct |
22 |
Correct |
5 ms |
7552 KB |
Output is correct |
23 |
Correct |
5 ms |
7424 KB |
Output is correct |
24 |
Correct |
6 ms |
7552 KB |
Output is correct |
25 |
Correct |
5 ms |
7424 KB |
Output is correct |
26 |
Correct |
5 ms |
7424 KB |
Output is correct |
27 |
Correct |
5 ms |
7424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
129 ms |
16632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7424 KB |
Output is correct |
2 |
Correct |
4 ms |
7424 KB |
Output is correct |
3 |
Correct |
5 ms |
7424 KB |
Output is correct |
4 |
Correct |
5 ms |
7424 KB |
Output is correct |
5 |
Correct |
5 ms |
7348 KB |
Output is correct |
6 |
Correct |
4 ms |
7424 KB |
Output is correct |
7 |
Correct |
6 ms |
7424 KB |
Output is correct |
8 |
Correct |
5 ms |
7424 KB |
Output is correct |
9 |
Correct |
6 ms |
7424 KB |
Output is correct |
10 |
Correct |
5 ms |
7424 KB |
Output is correct |
11 |
Correct |
4 ms |
7424 KB |
Output is correct |
12 |
Correct |
6 ms |
7424 KB |
Output is correct |
13 |
Correct |
5 ms |
7424 KB |
Output is correct |
14 |
Correct |
6 ms |
7424 KB |
Output is correct |
15 |
Correct |
6 ms |
7424 KB |
Output is correct |
16 |
Correct |
6 ms |
7424 KB |
Output is correct |
17 |
Correct |
6 ms |
7424 KB |
Output is correct |
18 |
Correct |
6 ms |
7424 KB |
Output is correct |
19 |
Correct |
5 ms |
7424 KB |
Output is correct |
20 |
Correct |
6 ms |
7424 KB |
Output is correct |
21 |
Correct |
6 ms |
7424 KB |
Output is correct |
22 |
Correct |
6 ms |
7424 KB |
Output is correct |
23 |
Correct |
6 ms |
7424 KB |
Output is correct |
24 |
Correct |
6 ms |
7424 KB |
Output is correct |
25 |
Correct |
6 ms |
7424 KB |
Output is correct |
26 |
Correct |
4 ms |
7424 KB |
Output is correct |
27 |
Correct |
5 ms |
7424 KB |
Output is correct |
28 |
Correct |
6 ms |
7424 KB |
Output is correct |
29 |
Correct |
5 ms |
7424 KB |
Output is correct |
30 |
Correct |
4 ms |
7424 KB |
Output is correct |
31 |
Correct |
4 ms |
7424 KB |
Output is correct |
32 |
Correct |
6 ms |
7424 KB |
Output is correct |
33 |
Correct |
6 ms |
7424 KB |
Output is correct |
34 |
Correct |
5 ms |
7424 KB |
Output is correct |
35 |
Correct |
4 ms |
7424 KB |
Output is correct |
36 |
Correct |
5 ms |
7424 KB |
Output is correct |
37 |
Correct |
6 ms |
7424 KB |
Output is correct |
38 |
Correct |
6 ms |
7424 KB |
Output is correct |
39 |
Correct |
5 ms |
7424 KB |
Output is correct |
40 |
Correct |
6 ms |
7424 KB |
Output is correct |
41 |
Correct |
4 ms |
7424 KB |
Output is correct |
42 |
Correct |
5 ms |
7424 KB |
Output is correct |
43 |
Correct |
7 ms |
7424 KB |
Output is correct |
44 |
Correct |
6 ms |
7424 KB |
Output is correct |
45 |
Correct |
5 ms |
7424 KB |
Output is correct |
46 |
Correct |
7 ms |
7424 KB |
Output is correct |
47 |
Correct |
7 ms |
7424 KB |
Output is correct |
48 |
Correct |
7 ms |
7424 KB |
Output is correct |
49 |
Correct |
4 ms |
7424 KB |
Output is correct |
50 |
Correct |
4 ms |
7424 KB |
Output is correct |
51 |
Correct |
5 ms |
7424 KB |
Output is correct |
52 |
Correct |
4 ms |
7424 KB |
Output is correct |
53 |
Correct |
4 ms |
7424 KB |
Output is correct |
54 |
Correct |
5 ms |
7424 KB |
Output is correct |
55 |
Correct |
4 ms |
7424 KB |
Output is correct |
56 |
Correct |
5 ms |
7424 KB |
Output is correct |
57 |
Correct |
4 ms |
7424 KB |
Output is correct |
58 |
Correct |
4 ms |
7424 KB |
Output is correct |
59 |
Correct |
5 ms |
7424 KB |
Output is correct |
60 |
Correct |
5 ms |
7424 KB |
Output is correct |
61 |
Correct |
4 ms |
7424 KB |
Output is correct |
62 |
Correct |
4 ms |
7424 KB |
Output is correct |
63 |
Correct |
4 ms |
7424 KB |
Output is correct |
64 |
Correct |
4 ms |
7424 KB |
Output is correct |
65 |
Correct |
4 ms |
7424 KB |
Output is correct |
66 |
Correct |
5 ms |
7424 KB |
Output is correct |
67 |
Correct |
5 ms |
7424 KB |
Output is correct |
68 |
Correct |
5 ms |
7424 KB |
Output is correct |
69 |
Correct |
5 ms |
7552 KB |
Output is correct |
70 |
Correct |
5 ms |
7552 KB |
Output is correct |
71 |
Correct |
5 ms |
7424 KB |
Output is correct |
72 |
Correct |
5 ms |
7424 KB |
Output is correct |
73 |
Correct |
5 ms |
7424 KB |
Output is correct |
74 |
Correct |
5 ms |
7424 KB |
Output is correct |
75 |
Correct |
4 ms |
7424 KB |
Output is correct |
76 |
Correct |
5 ms |
7424 KB |
Output is correct |
77 |
Correct |
5 ms |
7424 KB |
Output is correct |
78 |
Correct |
5 ms |
7424 KB |
Output is correct |
79 |
Correct |
6 ms |
7424 KB |
Output is correct |
80 |
Correct |
8 ms |
7424 KB |
Output is correct |
81 |
Correct |
5 ms |
7424 KB |
Output is correct |
82 |
Correct |
6 ms |
7552 KB |
Output is correct |
83 |
Correct |
5 ms |
7552 KB |
Output is correct |
84 |
Correct |
5 ms |
7552 KB |
Output is correct |
85 |
Correct |
5 ms |
7424 KB |
Output is correct |
86 |
Correct |
7 ms |
7440 KB |
Output is correct |
87 |
Correct |
6 ms |
7424 KB |
Output is correct |
88 |
Correct |
7 ms |
7424 KB |
Output is correct |
89 |
Correct |
6 ms |
7424 KB |
Output is correct |
90 |
Correct |
5 ms |
7424 KB |
Output is correct |
91 |
Correct |
6 ms |
7424 KB |
Output is correct |
92 |
Correct |
6 ms |
7552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7424 KB |
Output is correct |
2 |
Correct |
4 ms |
7424 KB |
Output is correct |
3 |
Correct |
5 ms |
7424 KB |
Output is correct |
4 |
Correct |
5 ms |
7424 KB |
Output is correct |
5 |
Correct |
5 ms |
7348 KB |
Output is correct |
6 |
Correct |
4 ms |
7424 KB |
Output is correct |
7 |
Correct |
6 ms |
7424 KB |
Output is correct |
8 |
Correct |
5 ms |
7424 KB |
Output is correct |
9 |
Correct |
6 ms |
7424 KB |
Output is correct |
10 |
Correct |
5 ms |
7424 KB |
Output is correct |
11 |
Correct |
4 ms |
7424 KB |
Output is correct |
12 |
Correct |
6 ms |
7424 KB |
Output is correct |
13 |
Correct |
5 ms |
7424 KB |
Output is correct |
14 |
Correct |
6 ms |
7424 KB |
Output is correct |
15 |
Correct |
6 ms |
7424 KB |
Output is correct |
16 |
Correct |
6 ms |
7424 KB |
Output is correct |
17 |
Correct |
6 ms |
7424 KB |
Output is correct |
18 |
Correct |
6 ms |
7424 KB |
Output is correct |
19 |
Correct |
5 ms |
7424 KB |
Output is correct |
20 |
Correct |
6 ms |
7424 KB |
Output is correct |
21 |
Correct |
6 ms |
7424 KB |
Output is correct |
22 |
Correct |
6 ms |
7424 KB |
Output is correct |
23 |
Correct |
6 ms |
7424 KB |
Output is correct |
24 |
Correct |
6 ms |
7424 KB |
Output is correct |
25 |
Correct |
6 ms |
7424 KB |
Output is correct |
26 |
Correct |
4 ms |
7424 KB |
Output is correct |
27 |
Correct |
5 ms |
7424 KB |
Output is correct |
28 |
Correct |
6 ms |
7424 KB |
Output is correct |
29 |
Correct |
5 ms |
7424 KB |
Output is correct |
30 |
Correct |
4 ms |
7424 KB |
Output is correct |
31 |
Correct |
4 ms |
7424 KB |
Output is correct |
32 |
Correct |
6 ms |
7424 KB |
Output is correct |
33 |
Correct |
6 ms |
7424 KB |
Output is correct |
34 |
Correct |
5 ms |
7424 KB |
Output is correct |
35 |
Correct |
4 ms |
7424 KB |
Output is correct |
36 |
Correct |
5 ms |
7424 KB |
Output is correct |
37 |
Correct |
6 ms |
7424 KB |
Output is correct |
38 |
Correct |
6 ms |
7424 KB |
Output is correct |
39 |
Correct |
5 ms |
7424 KB |
Output is correct |
40 |
Correct |
6 ms |
7424 KB |
Output is correct |
41 |
Correct |
4 ms |
7424 KB |
Output is correct |
42 |
Correct |
5 ms |
7424 KB |
Output is correct |
43 |
Correct |
7 ms |
7424 KB |
Output is correct |
44 |
Correct |
6 ms |
7424 KB |
Output is correct |
45 |
Correct |
5 ms |
7424 KB |
Output is correct |
46 |
Correct |
7 ms |
7424 KB |
Output is correct |
47 |
Correct |
7 ms |
7424 KB |
Output is correct |
48 |
Correct |
7 ms |
7424 KB |
Output is correct |
49 |
Correct |
4 ms |
7424 KB |
Output is correct |
50 |
Correct |
4 ms |
7424 KB |
Output is correct |
51 |
Correct |
5 ms |
7424 KB |
Output is correct |
52 |
Correct |
4 ms |
7424 KB |
Output is correct |
53 |
Correct |
4 ms |
7424 KB |
Output is correct |
54 |
Correct |
5 ms |
7424 KB |
Output is correct |
55 |
Correct |
4 ms |
7424 KB |
Output is correct |
56 |
Correct |
5 ms |
7424 KB |
Output is correct |
57 |
Correct |
4 ms |
7424 KB |
Output is correct |
58 |
Correct |
4 ms |
7424 KB |
Output is correct |
59 |
Correct |
5 ms |
7424 KB |
Output is correct |
60 |
Correct |
5 ms |
7424 KB |
Output is correct |
61 |
Correct |
4 ms |
7424 KB |
Output is correct |
62 |
Correct |
4 ms |
7424 KB |
Output is correct |
63 |
Correct |
4 ms |
7424 KB |
Output is correct |
64 |
Correct |
4 ms |
7424 KB |
Output is correct |
65 |
Correct |
4 ms |
7424 KB |
Output is correct |
66 |
Incorrect |
69 ms |
20592 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |