#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 25;
vector <int> adj[MAXN];
int n, m;
int dep[MAXN], low[MAXN];
vector <int> adj2[MAXN];
int cnt, sze2;
long long ans;
vector <int> cur;
void dfs (int pos, int par, int tt) {
dep[pos] = low[pos] = tt; cur.push_back(pos);
sze2++;
for (auto j : adj[pos]) {
if (j == par) continue;
if (dep[j] != -1) {
low[pos] = min(low[pos], dep[j]);
} else {
dfs(j, pos, tt + 1);
low[pos] = min(low[pos], low[j]);
if (low[j] >= dep[pos]) {
++cnt;
adj2[pos].push_back(n + cnt);
while (adj2[n + cnt].empty() || adj2[n + cnt].back() != j) {
adj2[n + cnt].push_back(cur.back());
cur.pop_back();
}
}
}
}
}
int sze[MAXN];
void dfs2 (int pos, int par) {
if (pos <= n) sze[pos] = 1;
long long l = adj2[pos].size();
for (auto j : adj2[pos]) {
dfs2(j, pos);
sze[pos] += sze[j];
if (pos > n) {
ans -= 1ll * sze[j] * (sze[j] - 1) * l;
}
}
if (pos > n) {
ans -= 1ll * (sze2 - sze[pos]) * (sze2 - sze[pos] - 1) * l;
}
}
int main () {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
memset(dep, -1, sizeof(dep));
for (int i = 1; i <= n; i++) {
if (-1 == dep[i]) {
sze2 = 0; cur.clear();
dfs(i, -1, 0);
ans += sze2 * (sze2 - 1) * (sze2 - 2);
dfs2(i, -1);
}
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
11868 KB |
Output is correct |
2 |
Correct |
3 ms |
11868 KB |
Output is correct |
3 |
Correct |
3 ms |
12020 KB |
Output is correct |
4 |
Correct |
3 ms |
11868 KB |
Output is correct |
5 |
Correct |
3 ms |
11868 KB |
Output is correct |
6 |
Correct |
3 ms |
11868 KB |
Output is correct |
7 |
Correct |
3 ms |
11868 KB |
Output is correct |
8 |
Correct |
3 ms |
11868 KB |
Output is correct |
9 |
Correct |
3 ms |
11868 KB |
Output is correct |
10 |
Correct |
3 ms |
11952 KB |
Output is correct |
11 |
Correct |
4 ms |
11984 KB |
Output is correct |
12 |
Correct |
3 ms |
11868 KB |
Output is correct |
13 |
Correct |
3 ms |
12024 KB |
Output is correct |
14 |
Correct |
2 ms |
11868 KB |
Output is correct |
15 |
Correct |
4 ms |
11868 KB |
Output is correct |
16 |
Correct |
3 ms |
11868 KB |
Output is correct |
17 |
Correct |
3 ms |
11868 KB |
Output is correct |
18 |
Correct |
3 ms |
11868 KB |
Output is correct |
19 |
Correct |
3 ms |
11864 KB |
Output is correct |
20 |
Correct |
3 ms |
11868 KB |
Output is correct |
21 |
Correct |
3 ms |
11864 KB |
Output is correct |
22 |
Correct |
3 ms |
11868 KB |
Output is correct |
23 |
Correct |
3 ms |
11864 KB |
Output is correct |
24 |
Correct |
3 ms |
11868 KB |
Output is correct |
25 |
Correct |
3 ms |
11868 KB |
Output is correct |
26 |
Correct |
3 ms |
11868 KB |
Output is correct |
27 |
Correct |
3 ms |
11868 KB |
Output is correct |
28 |
Correct |
4 ms |
11956 KB |
Output is correct |
29 |
Correct |
4 ms |
11864 KB |
Output is correct |
30 |
Correct |
3 ms |
11868 KB |
Output is correct |
31 |
Correct |
3 ms |
11868 KB |
Output is correct |
32 |
Correct |
3 ms |
11864 KB |
Output is correct |
33 |
Correct |
3 ms |
11868 KB |
Output is correct |
34 |
Correct |
3 ms |
11868 KB |
Output is correct |
35 |
Correct |
3 ms |
12028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
11868 KB |
Output is correct |
2 |
Correct |
3 ms |
11868 KB |
Output is correct |
3 |
Correct |
3 ms |
12020 KB |
Output is correct |
4 |
Correct |
3 ms |
11868 KB |
Output is correct |
5 |
Correct |
3 ms |
11868 KB |
Output is correct |
6 |
Correct |
3 ms |
11868 KB |
Output is correct |
7 |
Correct |
3 ms |
11868 KB |
Output is correct |
8 |
Correct |
3 ms |
11868 KB |
Output is correct |
9 |
Correct |
3 ms |
11868 KB |
Output is correct |
10 |
Correct |
3 ms |
11952 KB |
Output is correct |
11 |
Correct |
4 ms |
11984 KB |
Output is correct |
12 |
Correct |
3 ms |
11868 KB |
Output is correct |
13 |
Correct |
3 ms |
12024 KB |
Output is correct |
14 |
Correct |
2 ms |
11868 KB |
Output is correct |
15 |
Correct |
4 ms |
11868 KB |
Output is correct |
16 |
Correct |
3 ms |
11868 KB |
Output is correct |
17 |
Correct |
3 ms |
11868 KB |
Output is correct |
18 |
Correct |
3 ms |
11868 KB |
Output is correct |
19 |
Correct |
3 ms |
11864 KB |
Output is correct |
20 |
Correct |
3 ms |
11868 KB |
Output is correct |
21 |
Correct |
3 ms |
11864 KB |
Output is correct |
22 |
Correct |
3 ms |
11868 KB |
Output is correct |
23 |
Correct |
3 ms |
11864 KB |
Output is correct |
24 |
Correct |
3 ms |
11868 KB |
Output is correct |
25 |
Correct |
3 ms |
11868 KB |
Output is correct |
26 |
Correct |
3 ms |
11868 KB |
Output is correct |
27 |
Correct |
3 ms |
11868 KB |
Output is correct |
28 |
Correct |
4 ms |
11956 KB |
Output is correct |
29 |
Correct |
4 ms |
11864 KB |
Output is correct |
30 |
Correct |
3 ms |
11868 KB |
Output is correct |
31 |
Correct |
3 ms |
11868 KB |
Output is correct |
32 |
Correct |
3 ms |
11864 KB |
Output is correct |
33 |
Correct |
3 ms |
11868 KB |
Output is correct |
34 |
Correct |
3 ms |
11868 KB |
Output is correct |
35 |
Correct |
3 ms |
12028 KB |
Output is correct |
36 |
Correct |
3 ms |
11868 KB |
Output is correct |
37 |
Correct |
3 ms |
11864 KB |
Output is correct |
38 |
Correct |
3 ms |
11864 KB |
Output is correct |
39 |
Correct |
3 ms |
11868 KB |
Output is correct |
40 |
Correct |
3 ms |
11868 KB |
Output is correct |
41 |
Correct |
3 ms |
11868 KB |
Output is correct |
42 |
Correct |
3 ms |
11868 KB |
Output is correct |
43 |
Correct |
4 ms |
11868 KB |
Output is correct |
44 |
Correct |
3 ms |
12020 KB |
Output is correct |
45 |
Correct |
3 ms |
11868 KB |
Output is correct |
46 |
Correct |
3 ms |
11868 KB |
Output is correct |
47 |
Correct |
3 ms |
11868 KB |
Output is correct |
48 |
Correct |
3 ms |
11868 KB |
Output is correct |
49 |
Correct |
3 ms |
11868 KB |
Output is correct |
50 |
Correct |
3 ms |
12020 KB |
Output is correct |
51 |
Correct |
3 ms |
12020 KB |
Output is correct |
52 |
Correct |
3 ms |
11868 KB |
Output is correct |
53 |
Correct |
3 ms |
11868 KB |
Output is correct |
54 |
Correct |
4 ms |
11868 KB |
Output is correct |
55 |
Correct |
3 ms |
11868 KB |
Output is correct |
56 |
Correct |
3 ms |
11868 KB |
Output is correct |
57 |
Correct |
3 ms |
11868 KB |
Output is correct |
58 |
Correct |
4 ms |
11868 KB |
Output is correct |
59 |
Correct |
3 ms |
11868 KB |
Output is correct |
60 |
Correct |
3 ms |
11868 KB |
Output is correct |
61 |
Correct |
3 ms |
11868 KB |
Output is correct |
62 |
Correct |
3 ms |
11868 KB |
Output is correct |
63 |
Correct |
4 ms |
11868 KB |
Output is correct |
64 |
Correct |
3 ms |
11868 KB |
Output is correct |
65 |
Correct |
3 ms |
11992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
39 ms |
25608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
11868 KB |
Output is correct |
2 |
Correct |
4 ms |
11868 KB |
Output is correct |
3 |
Correct |
3 ms |
11868 KB |
Output is correct |
4 |
Correct |
3 ms |
12124 KB |
Output is correct |
5 |
Correct |
3 ms |
12124 KB |
Output is correct |
6 |
Correct |
4 ms |
12124 KB |
Output is correct |
7 |
Correct |
3 ms |
12124 KB |
Output is correct |
8 |
Correct |
3 ms |
12124 KB |
Output is correct |
9 |
Correct |
4 ms |
12128 KB |
Output is correct |
10 |
Correct |
3 ms |
11864 KB |
Output is correct |
11 |
Correct |
3 ms |
11868 KB |
Output is correct |
12 |
Correct |
3 ms |
11868 KB |
Output is correct |
13 |
Correct |
4 ms |
12096 KB |
Output is correct |
14 |
Correct |
3 ms |
12064 KB |
Output is correct |
15 |
Correct |
3 ms |
11872 KB |
Output is correct |
16 |
Correct |
4 ms |
11996 KB |
Output is correct |
17 |
Correct |
3 ms |
11868 KB |
Output is correct |
18 |
Correct |
3 ms |
11876 KB |
Output is correct |
19 |
Correct |
3 ms |
11868 KB |
Output is correct |
20 |
Correct |
3 ms |
11864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
43 ms |
20048 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
11868 KB |
Output is correct |
2 |
Correct |
3 ms |
11980 KB |
Output is correct |
3 |
Correct |
3 ms |
11868 KB |
Output is correct |
4 |
Correct |
3 ms |
11932 KB |
Output is correct |
5 |
Correct |
3 ms |
11868 KB |
Output is correct |
6 |
Correct |
3 ms |
11868 KB |
Output is correct |
7 |
Correct |
3 ms |
11864 KB |
Output is correct |
8 |
Correct |
3 ms |
11864 KB |
Output is correct |
9 |
Correct |
3 ms |
11868 KB |
Output is correct |
10 |
Correct |
3 ms |
11868 KB |
Output is correct |
11 |
Correct |
3 ms |
11864 KB |
Output is correct |
12 |
Correct |
3 ms |
12124 KB |
Output is correct |
13 |
Correct |
3 ms |
12124 KB |
Output is correct |
14 |
Correct |
3 ms |
12124 KB |
Output is correct |
15 |
Correct |
4 ms |
12124 KB |
Output is correct |
16 |
Correct |
3 ms |
11960 KB |
Output is correct |
17 |
Correct |
3 ms |
11868 KB |
Output is correct |
18 |
Correct |
4 ms |
11868 KB |
Output is correct |
19 |
Correct |
3 ms |
11868 KB |
Output is correct |
20 |
Correct |
4 ms |
11868 KB |
Output is correct |
21 |
Correct |
3 ms |
11868 KB |
Output is correct |
22 |
Correct |
3 ms |
12036 KB |
Output is correct |
23 |
Correct |
3 ms |
11868 KB |
Output is correct |
24 |
Correct |
4 ms |
11868 KB |
Output is correct |
25 |
Correct |
3 ms |
11868 KB |
Output is correct |
26 |
Correct |
3 ms |
11868 KB |
Output is correct |
27 |
Correct |
3 ms |
11952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
44 ms |
20052 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
11868 KB |
Output is correct |
2 |
Correct |
3 ms |
11868 KB |
Output is correct |
3 |
Correct |
3 ms |
12020 KB |
Output is correct |
4 |
Correct |
3 ms |
11868 KB |
Output is correct |
5 |
Correct |
3 ms |
11868 KB |
Output is correct |
6 |
Correct |
3 ms |
11868 KB |
Output is correct |
7 |
Correct |
3 ms |
11868 KB |
Output is correct |
8 |
Correct |
3 ms |
11868 KB |
Output is correct |
9 |
Correct |
3 ms |
11868 KB |
Output is correct |
10 |
Correct |
3 ms |
11952 KB |
Output is correct |
11 |
Correct |
4 ms |
11984 KB |
Output is correct |
12 |
Correct |
3 ms |
11868 KB |
Output is correct |
13 |
Correct |
3 ms |
12024 KB |
Output is correct |
14 |
Correct |
2 ms |
11868 KB |
Output is correct |
15 |
Correct |
4 ms |
11868 KB |
Output is correct |
16 |
Correct |
3 ms |
11868 KB |
Output is correct |
17 |
Correct |
3 ms |
11868 KB |
Output is correct |
18 |
Correct |
3 ms |
11868 KB |
Output is correct |
19 |
Correct |
3 ms |
11864 KB |
Output is correct |
20 |
Correct |
3 ms |
11868 KB |
Output is correct |
21 |
Correct |
3 ms |
11864 KB |
Output is correct |
22 |
Correct |
3 ms |
11868 KB |
Output is correct |
23 |
Correct |
3 ms |
11864 KB |
Output is correct |
24 |
Correct |
3 ms |
11868 KB |
Output is correct |
25 |
Correct |
3 ms |
11868 KB |
Output is correct |
26 |
Correct |
3 ms |
11868 KB |
Output is correct |
27 |
Correct |
3 ms |
11868 KB |
Output is correct |
28 |
Correct |
4 ms |
11956 KB |
Output is correct |
29 |
Correct |
4 ms |
11864 KB |
Output is correct |
30 |
Correct |
3 ms |
11868 KB |
Output is correct |
31 |
Correct |
3 ms |
11868 KB |
Output is correct |
32 |
Correct |
3 ms |
11864 KB |
Output is correct |
33 |
Correct |
3 ms |
11868 KB |
Output is correct |
34 |
Correct |
3 ms |
11868 KB |
Output is correct |
35 |
Correct |
3 ms |
12028 KB |
Output is correct |
36 |
Correct |
3 ms |
11868 KB |
Output is correct |
37 |
Correct |
3 ms |
11864 KB |
Output is correct |
38 |
Correct |
3 ms |
11864 KB |
Output is correct |
39 |
Correct |
3 ms |
11868 KB |
Output is correct |
40 |
Correct |
3 ms |
11868 KB |
Output is correct |
41 |
Correct |
3 ms |
11868 KB |
Output is correct |
42 |
Correct |
3 ms |
11868 KB |
Output is correct |
43 |
Correct |
4 ms |
11868 KB |
Output is correct |
44 |
Correct |
3 ms |
12020 KB |
Output is correct |
45 |
Correct |
3 ms |
11868 KB |
Output is correct |
46 |
Correct |
3 ms |
11868 KB |
Output is correct |
47 |
Correct |
3 ms |
11868 KB |
Output is correct |
48 |
Correct |
3 ms |
11868 KB |
Output is correct |
49 |
Correct |
3 ms |
11868 KB |
Output is correct |
50 |
Correct |
3 ms |
12020 KB |
Output is correct |
51 |
Correct |
3 ms |
12020 KB |
Output is correct |
52 |
Correct |
3 ms |
11868 KB |
Output is correct |
53 |
Correct |
3 ms |
11868 KB |
Output is correct |
54 |
Correct |
4 ms |
11868 KB |
Output is correct |
55 |
Correct |
3 ms |
11868 KB |
Output is correct |
56 |
Correct |
3 ms |
11868 KB |
Output is correct |
57 |
Correct |
3 ms |
11868 KB |
Output is correct |
58 |
Correct |
4 ms |
11868 KB |
Output is correct |
59 |
Correct |
3 ms |
11868 KB |
Output is correct |
60 |
Correct |
3 ms |
11868 KB |
Output is correct |
61 |
Correct |
3 ms |
11868 KB |
Output is correct |
62 |
Correct |
3 ms |
11868 KB |
Output is correct |
63 |
Correct |
4 ms |
11868 KB |
Output is correct |
64 |
Correct |
3 ms |
11868 KB |
Output is correct |
65 |
Correct |
3 ms |
11992 KB |
Output is correct |
66 |
Correct |
3 ms |
11864 KB |
Output is correct |
67 |
Correct |
3 ms |
11868 KB |
Output is correct |
68 |
Correct |
3 ms |
11868 KB |
Output is correct |
69 |
Correct |
4 ms |
11952 KB |
Output is correct |
70 |
Correct |
4 ms |
12036 KB |
Output is correct |
71 |
Correct |
3 ms |
11868 KB |
Output is correct |
72 |
Correct |
4 ms |
12036 KB |
Output is correct |
73 |
Correct |
3 ms |
11864 KB |
Output is correct |
74 |
Correct |
3 ms |
11960 KB |
Output is correct |
75 |
Correct |
3 ms |
11868 KB |
Output is correct |
76 |
Correct |
3 ms |
12020 KB |
Output is correct |
77 |
Correct |
3 ms |
11868 KB |
Output is correct |
78 |
Correct |
3 ms |
11868 KB |
Output is correct |
79 |
Correct |
3 ms |
11868 KB |
Output is correct |
80 |
Correct |
3 ms |
11868 KB |
Output is correct |
81 |
Correct |
3 ms |
11868 KB |
Output is correct |
82 |
Correct |
3 ms |
12124 KB |
Output is correct |
83 |
Correct |
3 ms |
11988 KB |
Output is correct |
84 |
Correct |
3 ms |
11868 KB |
Output is correct |
85 |
Correct |
3 ms |
11868 KB |
Output is correct |
86 |
Correct |
3 ms |
11864 KB |
Output is correct |
87 |
Correct |
3 ms |
11868 KB |
Output is correct |
88 |
Correct |
4 ms |
11868 KB |
Output is correct |
89 |
Correct |
3 ms |
11868 KB |
Output is correct |
90 |
Correct |
3 ms |
11864 KB |
Output is correct |
91 |
Correct |
4 ms |
12124 KB |
Output is correct |
92 |
Correct |
3 ms |
11868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
11868 KB |
Output is correct |
2 |
Correct |
3 ms |
11868 KB |
Output is correct |
3 |
Correct |
3 ms |
12020 KB |
Output is correct |
4 |
Correct |
3 ms |
11868 KB |
Output is correct |
5 |
Correct |
3 ms |
11868 KB |
Output is correct |
6 |
Correct |
3 ms |
11868 KB |
Output is correct |
7 |
Correct |
3 ms |
11868 KB |
Output is correct |
8 |
Correct |
3 ms |
11868 KB |
Output is correct |
9 |
Correct |
3 ms |
11868 KB |
Output is correct |
10 |
Correct |
3 ms |
11952 KB |
Output is correct |
11 |
Correct |
4 ms |
11984 KB |
Output is correct |
12 |
Correct |
3 ms |
11868 KB |
Output is correct |
13 |
Correct |
3 ms |
12024 KB |
Output is correct |
14 |
Correct |
2 ms |
11868 KB |
Output is correct |
15 |
Correct |
4 ms |
11868 KB |
Output is correct |
16 |
Correct |
3 ms |
11868 KB |
Output is correct |
17 |
Correct |
3 ms |
11868 KB |
Output is correct |
18 |
Correct |
3 ms |
11868 KB |
Output is correct |
19 |
Correct |
3 ms |
11864 KB |
Output is correct |
20 |
Correct |
3 ms |
11868 KB |
Output is correct |
21 |
Correct |
3 ms |
11864 KB |
Output is correct |
22 |
Correct |
3 ms |
11868 KB |
Output is correct |
23 |
Correct |
3 ms |
11864 KB |
Output is correct |
24 |
Correct |
3 ms |
11868 KB |
Output is correct |
25 |
Correct |
3 ms |
11868 KB |
Output is correct |
26 |
Correct |
3 ms |
11868 KB |
Output is correct |
27 |
Correct |
3 ms |
11868 KB |
Output is correct |
28 |
Correct |
4 ms |
11956 KB |
Output is correct |
29 |
Correct |
4 ms |
11864 KB |
Output is correct |
30 |
Correct |
3 ms |
11868 KB |
Output is correct |
31 |
Correct |
3 ms |
11868 KB |
Output is correct |
32 |
Correct |
3 ms |
11864 KB |
Output is correct |
33 |
Correct |
3 ms |
11868 KB |
Output is correct |
34 |
Correct |
3 ms |
11868 KB |
Output is correct |
35 |
Correct |
3 ms |
12028 KB |
Output is correct |
36 |
Correct |
3 ms |
11868 KB |
Output is correct |
37 |
Correct |
3 ms |
11864 KB |
Output is correct |
38 |
Correct |
3 ms |
11864 KB |
Output is correct |
39 |
Correct |
3 ms |
11868 KB |
Output is correct |
40 |
Correct |
3 ms |
11868 KB |
Output is correct |
41 |
Correct |
3 ms |
11868 KB |
Output is correct |
42 |
Correct |
3 ms |
11868 KB |
Output is correct |
43 |
Correct |
4 ms |
11868 KB |
Output is correct |
44 |
Correct |
3 ms |
12020 KB |
Output is correct |
45 |
Correct |
3 ms |
11868 KB |
Output is correct |
46 |
Correct |
3 ms |
11868 KB |
Output is correct |
47 |
Correct |
3 ms |
11868 KB |
Output is correct |
48 |
Correct |
3 ms |
11868 KB |
Output is correct |
49 |
Correct |
3 ms |
11868 KB |
Output is correct |
50 |
Correct |
3 ms |
12020 KB |
Output is correct |
51 |
Correct |
3 ms |
12020 KB |
Output is correct |
52 |
Correct |
3 ms |
11868 KB |
Output is correct |
53 |
Correct |
3 ms |
11868 KB |
Output is correct |
54 |
Correct |
4 ms |
11868 KB |
Output is correct |
55 |
Correct |
3 ms |
11868 KB |
Output is correct |
56 |
Correct |
3 ms |
11868 KB |
Output is correct |
57 |
Correct |
3 ms |
11868 KB |
Output is correct |
58 |
Correct |
4 ms |
11868 KB |
Output is correct |
59 |
Correct |
3 ms |
11868 KB |
Output is correct |
60 |
Correct |
3 ms |
11868 KB |
Output is correct |
61 |
Correct |
3 ms |
11868 KB |
Output is correct |
62 |
Correct |
3 ms |
11868 KB |
Output is correct |
63 |
Correct |
4 ms |
11868 KB |
Output is correct |
64 |
Correct |
3 ms |
11868 KB |
Output is correct |
65 |
Correct |
3 ms |
11992 KB |
Output is correct |
66 |
Incorrect |
39 ms |
25608 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |