#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int n, m;
vector<int> g[N], comp;
bool vis[N], possible[105][105][105];
void dfs_brute(int v, int y, int z){
if (v == z) return;
vis[v] = 1;
for (int u : g[v])
if (!vis[u]) dfs_brute(u, y, z);
}
void dfs(int v){
vis[v] = 1;
comp.push_back(v);
for (int u : g[v]){
if (vis[u]) continue;
dfs(u);
}
}
int main(){
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);
}
int total = n * (n - 1) * (n - 2);
if (n <= 100 and m <= 100){
for (int u = 1; u <= n; u ++){
for (int v = 1; v <= n; v ++){
for (int e = 1; e <= n; e ++){
for (int x = 1; x <= n; x ++)
vis[x] = 0;
dfs_brute(u, v, e);
if (vis[v])
possible[u][v][e] = 1;
}
}
}
for (int c = 1; c <= n; c ++){
for (int s = 1; s <= n; s ++){
for (int f = 1; f <= n; f ++){
if (c == s or c == f or s == f) continue;
bool bad = 0;
for (int v = 1; v <= n; v ++){
if (v == c) continue;
if (!possible[s][c][v] and !possible[c][f][v])
bad = 1;
}
total -= bad;
}
}
}
cout << total << endl;
return 0;
}
ll ans = 0;
for (int v = 1; v <= n; v ++){
if (vis[v]) continue;
comp.clear();
dfs(v);
int edges = 0;
for (int x : comp)
edges += g[x].size();
edges /= 2;
ll nodes = comp.size();
if (nodes == edges){
ans += nodes * (nodes - 1) * (nodes - 2);
continue;
}
ans += (nodes * (nodes - 1) * (nodes - 2)) / 3;
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2788 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
4 |
Correct |
1 ms |
2784 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2664 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2792 KB |
Output is correct |
18 |
Correct |
1 ms |
2820 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
3676 KB |
Output is correct |
25 |
Correct |
1 ms |
2692 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
1 ms |
3676 KB |
Output is correct |
29 |
Correct |
1 ms |
2792 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
1 ms |
2652 KB |
Output is correct |
32 |
Correct |
1 ms |
2652 KB |
Output is correct |
33 |
Correct |
1 ms |
2652 KB |
Output is correct |
34 |
Correct |
1 ms |
3676 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2788 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
4 |
Correct |
1 ms |
2784 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2664 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2792 KB |
Output is correct |
18 |
Correct |
1 ms |
2820 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
3676 KB |
Output is correct |
25 |
Correct |
1 ms |
2692 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
1 ms |
3676 KB |
Output is correct |
29 |
Correct |
1 ms |
2792 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
1 ms |
2652 KB |
Output is correct |
32 |
Correct |
1 ms |
2652 KB |
Output is correct |
33 |
Correct |
1 ms |
2652 KB |
Output is correct |
34 |
Correct |
1 ms |
3676 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
6 ms |
2904 KB |
Output is correct |
37 |
Correct |
6 ms |
2908 KB |
Output is correct |
38 |
Correct |
20 ms |
3216 KB |
Output is correct |
39 |
Correct |
31 ms |
3164 KB |
Output is correct |
40 |
Correct |
38 ms |
3932 KB |
Output is correct |
41 |
Correct |
5 ms |
2908 KB |
Output is correct |
42 |
Correct |
5 ms |
2996 KB |
Output is correct |
43 |
Correct |
5 ms |
2996 KB |
Output is correct |
44 |
Correct |
6 ms |
2912 KB |
Output is correct |
45 |
Correct |
5 ms |
2912 KB |
Output is correct |
46 |
Correct |
6 ms |
2908 KB |
Output is correct |
47 |
Correct |
1 ms |
2792 KB |
Output is correct |
48 |
Correct |
5 ms |
2792 KB |
Output is correct |
49 |
Correct |
7 ms |
2908 KB |
Output is correct |
50 |
Correct |
5 ms |
2908 KB |
Output is correct |
51 |
Correct |
24 ms |
3932 KB |
Output is correct |
52 |
Correct |
26 ms |
3256 KB |
Output is correct |
53 |
Correct |
30 ms |
3184 KB |
Output is correct |
54 |
Correct |
28 ms |
3164 KB |
Output is correct |
55 |
Correct |
29 ms |
3156 KB |
Output is correct |
56 |
Correct |
30 ms |
3164 KB |
Output is correct |
57 |
Correct |
30 ms |
3164 KB |
Output is correct |
58 |
Correct |
27 ms |
3164 KB |
Output is correct |
59 |
Correct |
19 ms |
3412 KB |
Output is correct |
60 |
Correct |
17 ms |
3160 KB |
Output is correct |
61 |
Correct |
10 ms |
3164 KB |
Output is correct |
62 |
Correct |
7 ms |
3176 KB |
Output is correct |
63 |
Correct |
26 ms |
3156 KB |
Output is correct |
64 |
Correct |
26 ms |
3164 KB |
Output is correct |
65 |
Correct |
25 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
12244 KB |
Output is correct |
2 |
Correct |
44 ms |
12240 KB |
Output is correct |
3 |
Correct |
43 ms |
9888 KB |
Output is correct |
4 |
Correct |
48 ms |
10968 KB |
Output is correct |
5 |
Correct |
43 ms |
9044 KB |
Output is correct |
6 |
Correct |
52 ms |
9132 KB |
Output is correct |
7 |
Correct |
39 ms |
8276 KB |
Output is correct |
8 |
Correct |
43 ms |
8664 KB |
Output is correct |
9 |
Correct |
43 ms |
8592 KB |
Output is correct |
10 |
Correct |
42 ms |
8156 KB |
Output is correct |
11 |
Correct |
34 ms |
6904 KB |
Output is correct |
12 |
Correct |
37 ms |
6748 KB |
Output is correct |
13 |
Correct |
30 ms |
6740 KB |
Output is correct |
14 |
Correct |
30 ms |
6556 KB |
Output is correct |
15 |
Correct |
23 ms |
5980 KB |
Output is correct |
16 |
Correct |
24 ms |
6028 KB |
Output is correct |
17 |
Correct |
2 ms |
2652 KB |
Output is correct |
18 |
Correct |
2 ms |
2908 KB |
Output is correct |
19 |
Correct |
1 ms |
3676 KB |
Output is correct |
20 |
Correct |
2 ms |
2792 KB |
Output is correct |
21 |
Correct |
2 ms |
2896 KB |
Output is correct |
22 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
42 ms |
7924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
40 ms |
7892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2788 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
4 |
Correct |
1 ms |
2784 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2664 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2792 KB |
Output is correct |
18 |
Correct |
1 ms |
2820 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
3676 KB |
Output is correct |
25 |
Correct |
1 ms |
2692 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
1 ms |
3676 KB |
Output is correct |
29 |
Correct |
1 ms |
2792 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
1 ms |
2652 KB |
Output is correct |
32 |
Correct |
1 ms |
2652 KB |
Output is correct |
33 |
Correct |
1 ms |
2652 KB |
Output is correct |
34 |
Correct |
1 ms |
3676 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
6 ms |
2904 KB |
Output is correct |
37 |
Correct |
6 ms |
2908 KB |
Output is correct |
38 |
Correct |
20 ms |
3216 KB |
Output is correct |
39 |
Correct |
31 ms |
3164 KB |
Output is correct |
40 |
Correct |
38 ms |
3932 KB |
Output is correct |
41 |
Correct |
5 ms |
2908 KB |
Output is correct |
42 |
Correct |
5 ms |
2996 KB |
Output is correct |
43 |
Correct |
5 ms |
2996 KB |
Output is correct |
44 |
Correct |
6 ms |
2912 KB |
Output is correct |
45 |
Correct |
5 ms |
2912 KB |
Output is correct |
46 |
Correct |
6 ms |
2908 KB |
Output is correct |
47 |
Correct |
1 ms |
2792 KB |
Output is correct |
48 |
Correct |
5 ms |
2792 KB |
Output is correct |
49 |
Correct |
7 ms |
2908 KB |
Output is correct |
50 |
Correct |
5 ms |
2908 KB |
Output is correct |
51 |
Correct |
24 ms |
3932 KB |
Output is correct |
52 |
Correct |
26 ms |
3256 KB |
Output is correct |
53 |
Correct |
30 ms |
3184 KB |
Output is correct |
54 |
Correct |
28 ms |
3164 KB |
Output is correct |
55 |
Correct |
29 ms |
3156 KB |
Output is correct |
56 |
Correct |
30 ms |
3164 KB |
Output is correct |
57 |
Correct |
30 ms |
3164 KB |
Output is correct |
58 |
Correct |
27 ms |
3164 KB |
Output is correct |
59 |
Correct |
19 ms |
3412 KB |
Output is correct |
60 |
Correct |
17 ms |
3160 KB |
Output is correct |
61 |
Correct |
10 ms |
3164 KB |
Output is correct |
62 |
Correct |
7 ms |
3176 KB |
Output is correct |
63 |
Correct |
26 ms |
3156 KB |
Output is correct |
64 |
Correct |
26 ms |
3164 KB |
Output is correct |
65 |
Correct |
25 ms |
3164 KB |
Output is correct |
66 |
Correct |
1 ms |
3676 KB |
Output is correct |
67 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
68 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2788 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
4 |
Correct |
1 ms |
2784 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2664 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2792 KB |
Output is correct |
18 |
Correct |
1 ms |
2820 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
3676 KB |
Output is correct |
25 |
Correct |
1 ms |
2692 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
1 ms |
3676 KB |
Output is correct |
29 |
Correct |
1 ms |
2792 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
1 ms |
2652 KB |
Output is correct |
32 |
Correct |
1 ms |
2652 KB |
Output is correct |
33 |
Correct |
1 ms |
2652 KB |
Output is correct |
34 |
Correct |
1 ms |
3676 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
6 ms |
2904 KB |
Output is correct |
37 |
Correct |
6 ms |
2908 KB |
Output is correct |
38 |
Correct |
20 ms |
3216 KB |
Output is correct |
39 |
Correct |
31 ms |
3164 KB |
Output is correct |
40 |
Correct |
38 ms |
3932 KB |
Output is correct |
41 |
Correct |
5 ms |
2908 KB |
Output is correct |
42 |
Correct |
5 ms |
2996 KB |
Output is correct |
43 |
Correct |
5 ms |
2996 KB |
Output is correct |
44 |
Correct |
6 ms |
2912 KB |
Output is correct |
45 |
Correct |
5 ms |
2912 KB |
Output is correct |
46 |
Correct |
6 ms |
2908 KB |
Output is correct |
47 |
Correct |
1 ms |
2792 KB |
Output is correct |
48 |
Correct |
5 ms |
2792 KB |
Output is correct |
49 |
Correct |
7 ms |
2908 KB |
Output is correct |
50 |
Correct |
5 ms |
2908 KB |
Output is correct |
51 |
Correct |
24 ms |
3932 KB |
Output is correct |
52 |
Correct |
26 ms |
3256 KB |
Output is correct |
53 |
Correct |
30 ms |
3184 KB |
Output is correct |
54 |
Correct |
28 ms |
3164 KB |
Output is correct |
55 |
Correct |
29 ms |
3156 KB |
Output is correct |
56 |
Correct |
30 ms |
3164 KB |
Output is correct |
57 |
Correct |
30 ms |
3164 KB |
Output is correct |
58 |
Correct |
27 ms |
3164 KB |
Output is correct |
59 |
Correct |
19 ms |
3412 KB |
Output is correct |
60 |
Correct |
17 ms |
3160 KB |
Output is correct |
61 |
Correct |
10 ms |
3164 KB |
Output is correct |
62 |
Correct |
7 ms |
3176 KB |
Output is correct |
63 |
Correct |
26 ms |
3156 KB |
Output is correct |
64 |
Correct |
26 ms |
3164 KB |
Output is correct |
65 |
Correct |
25 ms |
3164 KB |
Output is correct |
66 |
Correct |
44 ms |
12244 KB |
Output is correct |
67 |
Correct |
44 ms |
12240 KB |
Output is correct |
68 |
Correct |
43 ms |
9888 KB |
Output is correct |
69 |
Correct |
48 ms |
10968 KB |
Output is correct |
70 |
Correct |
43 ms |
9044 KB |
Output is correct |
71 |
Correct |
52 ms |
9132 KB |
Output is correct |
72 |
Correct |
39 ms |
8276 KB |
Output is correct |
73 |
Correct |
43 ms |
8664 KB |
Output is correct |
74 |
Correct |
43 ms |
8592 KB |
Output is correct |
75 |
Correct |
42 ms |
8156 KB |
Output is correct |
76 |
Correct |
34 ms |
6904 KB |
Output is correct |
77 |
Correct |
37 ms |
6748 KB |
Output is correct |
78 |
Correct |
30 ms |
6740 KB |
Output is correct |
79 |
Correct |
30 ms |
6556 KB |
Output is correct |
80 |
Correct |
23 ms |
5980 KB |
Output is correct |
81 |
Correct |
24 ms |
6028 KB |
Output is correct |
82 |
Correct |
2 ms |
2652 KB |
Output is correct |
83 |
Correct |
2 ms |
2908 KB |
Output is correct |
84 |
Correct |
1 ms |
3676 KB |
Output is correct |
85 |
Correct |
2 ms |
2792 KB |
Output is correct |
86 |
Correct |
2 ms |
2896 KB |
Output is correct |
87 |
Correct |
2 ms |
2652 KB |
Output is correct |
88 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
89 |
Halted |
0 ms |
0 KB |
- |