#include <bits/stdc++.h>
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
using namespace std;
const int N = 1e5 + 5;
vector<int> g2[N], t[N], g[N];
int tin[N], mt[N], col[N], sz[N], sum[N];
int timer = 0, n, m;
bool used[N];
void dfs(int node, int anc) {
used[node] = 1;
tin[node] = ++timer;
mt[node] = tin[node];
for (int to : g[node]) {
if (to != anc) {
if (!used[to]) {
dfs(to, node);
}
mt[node] = min(mt[node], mt[to]);
if (mt[to] <= tin[node]) {
g2[node].push_back(to);
g2[to].push_back(node);
}
}
}
}
void deep(int node, int c) {
col[node] = c;
used[node] = 1;
sz[col[node]]++;
for (int to : g2[node]) {
if (!used[to]) {
deep(to, c);
}
}
for (int to : g[node]) {
if (used[to] && col[to] != col[node]) {
t[col[node]].push_back(col[to]);
t[col[to]].push_back(col[node]);
}
}
}
ll ans = 0;
int walk(int node, int anc) {
int s = sz[node];
for (int to : t[node]) {
if (to != anc) {
s += walk(to, node);
}
}
return s;
}
void dive(int node, int anc, int whole) {
ans += sz[node] * (ll)(sz[node] - 1) * (sz[node] - 2);
sum[node] = sz[node];
used[node] = 1;
for (int to : t[node]) {
if (to != anc) {
dive(to, node, whole);
sum[node] += sum[to];
}
}
for (int to : t[node]) {
int s = 0;
if (to == anc)
s = whole - sum[node];
else
s = sum[to];
ans += sz[node] * (ll)s * (whole - s - sz[node]);
ans += (sz[node] * (ll)(sz[node] - 1) - sz[node] + 1) * s * 2;
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--, b--;
g[a].push_back(b);
g[b].push_back(a);
}
for (int i = 0; i < n; i++) {
if (!used[i]) {
dfs(i, -1);
}
}
int cc = 0;
fill(used, used + n, 0);
for (int i = 0; i < n; i++) {
if (!used[i]) {
deep(i, cc++);
}
}
fill(used, used + cc, 0);
for (int i = 0; i < cc; i++) {
if (!used[i]) {
dive(i, -1, walk(i, -1));
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
9 ms |
7416 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
8 ms |
7416 KB |
Output is correct |
5 |
Correct |
8 ms |
7416 KB |
Output is correct |
6 |
Correct |
7 ms |
7416 KB |
Output is correct |
7 |
Incorrect |
8 ms |
7416 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
9 ms |
7416 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
8 ms |
7416 KB |
Output is correct |
5 |
Correct |
8 ms |
7416 KB |
Output is correct |
6 |
Correct |
7 ms |
7416 KB |
Output is correct |
7 |
Incorrect |
8 ms |
7416 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
125 ms |
21264 KB |
Output is correct |
2 |
Correct |
98 ms |
21232 KB |
Output is correct |
3 |
Correct |
94 ms |
19192 KB |
Output is correct |
4 |
Correct |
101 ms |
19832 KB |
Output is correct |
5 |
Correct |
92 ms |
17724 KB |
Output is correct |
6 |
Correct |
97 ms |
18424 KB |
Output is correct |
7 |
Correct |
97 ms |
17272 KB |
Output is correct |
8 |
Correct |
94 ms |
17528 KB |
Output is correct |
9 |
Correct |
93 ms |
16376 KB |
Output is correct |
10 |
Correct |
91 ms |
16632 KB |
Output is correct |
11 |
Correct |
81 ms |
15352 KB |
Output is correct |
12 |
Correct |
82 ms |
15224 KB |
Output is correct |
13 |
Correct |
73 ms |
15224 KB |
Output is correct |
14 |
Correct |
75 ms |
14968 KB |
Output is correct |
15 |
Correct |
55 ms |
14456 KB |
Output is correct |
16 |
Correct |
59 ms |
14200 KB |
Output is correct |
17 |
Correct |
12 ms |
9464 KB |
Output is correct |
18 |
Correct |
12 ms |
9400 KB |
Output is correct |
19 |
Correct |
11 ms |
9464 KB |
Output is correct |
20 |
Correct |
12 ms |
9464 KB |
Output is correct |
21 |
Correct |
12 ms |
9464 KB |
Output is correct |
22 |
Correct |
11 ms |
9464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7544 KB |
Output is correct |
2 |
Correct |
8 ms |
7544 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
10 ms |
7672 KB |
Output is correct |
5 |
Correct |
9 ms |
7544 KB |
Output is correct |
6 |
Correct |
9 ms |
7544 KB |
Output is correct |
7 |
Correct |
11 ms |
7544 KB |
Output is correct |
8 |
Correct |
8 ms |
7544 KB |
Output is correct |
9 |
Correct |
8 ms |
7544 KB |
Output is correct |
10 |
Correct |
8 ms |
7544 KB |
Output is correct |
11 |
Correct |
8 ms |
7544 KB |
Output is correct |
12 |
Correct |
10 ms |
7516 KB |
Output is correct |
13 |
Correct |
10 ms |
7544 KB |
Output is correct |
14 |
Correct |
8 ms |
7416 KB |
Output is correct |
15 |
Correct |
9 ms |
7544 KB |
Output is correct |
16 |
Correct |
10 ms |
7416 KB |
Output is correct |
17 |
Correct |
9 ms |
7544 KB |
Output is correct |
18 |
Correct |
10 ms |
7544 KB |
Output is correct |
19 |
Correct |
10 ms |
7544 KB |
Output is correct |
20 |
Correct |
8 ms |
7544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
126 ms |
15960 KB |
Output is correct |
2 |
Correct |
113 ms |
15840 KB |
Output is correct |
3 |
Correct |
124 ms |
15864 KB |
Output is correct |
4 |
Correct |
129 ms |
15864 KB |
Output is correct |
5 |
Correct |
94 ms |
16036 KB |
Output is correct |
6 |
Correct |
119 ms |
20820 KB |
Output is correct |
7 |
Correct |
99 ms |
19064 KB |
Output is correct |
8 |
Correct |
131 ms |
18172 KB |
Output is correct |
9 |
Correct |
132 ms |
17400 KB |
Output is correct |
10 |
Correct |
105 ms |
15968 KB |
Output is correct |
11 |
Correct |
92 ms |
15964 KB |
Output is correct |
12 |
Correct |
88 ms |
15864 KB |
Output is correct |
13 |
Correct |
88 ms |
15864 KB |
Output is correct |
14 |
Correct |
87 ms |
15712 KB |
Output is correct |
15 |
Correct |
76 ms |
15480 KB |
Output is correct |
16 |
Correct |
52 ms |
14072 KB |
Output is correct |
17 |
Correct |
66 ms |
16624 KB |
Output is correct |
18 |
Correct |
70 ms |
16504 KB |
Output is correct |
19 |
Correct |
67 ms |
17004 KB |
Output is correct |
20 |
Correct |
63 ms |
16504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7544 KB |
Output is correct |
2 |
Correct |
8 ms |
7516 KB |
Output is correct |
3 |
Incorrect |
8 ms |
7516 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
15992 KB |
Output is correct |
2 |
Correct |
97 ms |
15756 KB |
Output is correct |
3 |
Incorrect |
106 ms |
16092 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
9 ms |
7416 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
8 ms |
7416 KB |
Output is correct |
5 |
Correct |
8 ms |
7416 KB |
Output is correct |
6 |
Correct |
7 ms |
7416 KB |
Output is correct |
7 |
Incorrect |
8 ms |
7416 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
9 ms |
7416 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
8 ms |
7416 KB |
Output is correct |
5 |
Correct |
8 ms |
7416 KB |
Output is correct |
6 |
Correct |
7 ms |
7416 KB |
Output is correct |
7 |
Incorrect |
8 ms |
7416 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |