#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 100 * 1000 + 23;
int n, m, ans;
vector<int> g[MAXN];
bitset<MAXN> mark, mirk;
//int ent(int x) { return x * (x - 1); }
int gs(int v, int p) {
int res = 1;
mark[v] = true;
for (auto i : g[v]) if (!mark[i]) res += gs(i, v);
return res;
}
int ds(int v, int p) {
int res = g[v].size();
mirk[v] = true;
for (auto i : g[v]) if (i != p && !mirk[i]) res += ds(i, v);
return res;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
g[--u].push_back(--v), g[v].push_back(u);
}
for (int i = 0; i < n; i++) if (!mark[i]) {
int x = gs(i, -1);
int y = ds(i, -1);
if (x * 2 == y) ans += x * (x - 1) * (x - 2);
else for (int i = 0; i < x; i++) ans += i * (x - i - 1) * 2;
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
11972 KB |
Output is correct |
2 |
Correct |
70 ms |
13300 KB |
Output is correct |
3 |
Correct |
89 ms |
10220 KB |
Output is correct |
4 |
Correct |
70 ms |
11676 KB |
Output is correct |
5 |
Correct |
68 ms |
9076 KB |
Output is correct |
6 |
Correct |
62 ms |
9052 KB |
Output is correct |
7 |
Correct |
60 ms |
8300 KB |
Output is correct |
8 |
Correct |
58 ms |
8680 KB |
Output is correct |
9 |
Correct |
64 ms |
7656 KB |
Output is correct |
10 |
Correct |
66 ms |
8284 KB |
Output is correct |
11 |
Correct |
43 ms |
6796 KB |
Output is correct |
12 |
Correct |
41 ms |
6708 KB |
Output is correct |
13 |
Correct |
43 ms |
6596 KB |
Output is correct |
14 |
Correct |
48 ms |
6380 KB |
Output is correct |
15 |
Correct |
36 ms |
5940 KB |
Output is correct |
16 |
Correct |
29 ms |
5864 KB |
Output is correct |
17 |
Correct |
3 ms |
2636 KB |
Output is correct |
18 |
Correct |
3 ms |
2636 KB |
Output is correct |
19 |
Correct |
3 ms |
2636 KB |
Output is correct |
20 |
Correct |
3 ms |
2636 KB |
Output is correct |
21 |
Correct |
3 ms |
2636 KB |
Output is correct |
22 |
Correct |
3 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
53 ms |
6320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
54 ms |
6412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |