#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int n, m, subsz[N], dp[N];
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, int p = -1){
vis[v] = 1;
comp.push_back(v);
subsz[v] = 1;
for (int u : g[v]){
if (vis[u]) continue;
dfs(u, v);
subsz[v] += subsz[u];
}
int cur = 0;
for (int u : g[v]){
if (u == p) continue;
dp[v] += subsz[u] * cur;
cur += subsz[u];
}
}
void dfs_up(int v, int p = -1){
for (int u : g[v]){
if (u == p) continue;
dfs_up(u, v);
}
dp[v] += (comp.size() - subsz[v]) * (subsz[v] - 1);
}
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;
}
dfs_up(v);
for (int u : comp)
ans += dp[u];
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
3676 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2800 KB |
Output is correct |
7 |
Correct |
2 ms |
2648 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 |
3676 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 |
3904 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2808 KB |
Output is correct |
19 |
Correct |
1 ms |
3676 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
2 ms |
2648 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 |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 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 |
2652 KB |
Output is correct |
29 |
Correct |
1 ms |
2652 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 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 |
2652 KB |
Output is correct |
35 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
3676 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2800 KB |
Output is correct |
7 |
Correct |
2 ms |
2648 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 |
3676 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 |
3904 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2808 KB |
Output is correct |
19 |
Correct |
1 ms |
3676 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
2 ms |
2648 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 |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 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 |
2652 KB |
Output is correct |
29 |
Correct |
1 ms |
2652 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 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 |
2652 KB |
Output is correct |
35 |
Correct |
2 ms |
2652 KB |
Output is correct |
36 |
Correct |
8 ms |
2908 KB |
Output is correct |
37 |
Correct |
6 ms |
2908 KB |
Output is correct |
38 |
Correct |
20 ms |
3160 KB |
Output is correct |
39 |
Correct |
29 ms |
3160 KB |
Output is correct |
40 |
Correct |
37 ms |
3156 KB |
Output is correct |
41 |
Correct |
6 ms |
2908 KB |
Output is correct |
42 |
Correct |
6 ms |
3004 KB |
Output is correct |
43 |
Correct |
6 ms |
2904 KB |
Output is correct |
44 |
Correct |
6 ms |
3016 KB |
Output is correct |
45 |
Correct |
6 ms |
3676 KB |
Output is correct |
46 |
Correct |
7 ms |
3676 KB |
Output is correct |
47 |
Correct |
2 ms |
2648 KB |
Output is correct |
48 |
Correct |
7 ms |
2904 KB |
Output is correct |
49 |
Correct |
5 ms |
2908 KB |
Output is correct |
50 |
Correct |
5 ms |
2908 KB |
Output is correct |
51 |
Correct |
28 ms |
3180 KB |
Output is correct |
52 |
Correct |
25 ms |
3152 KB |
Output is correct |
53 |
Correct |
29 ms |
3076 KB |
Output is correct |
54 |
Correct |
30 ms |
3152 KB |
Output is correct |
55 |
Correct |
27 ms |
3164 KB |
Output is correct |
56 |
Correct |
34 ms |
3104 KB |
Output is correct |
57 |
Correct |
26 ms |
3164 KB |
Output is correct |
58 |
Correct |
26 ms |
3272 KB |
Output is correct |
59 |
Correct |
20 ms |
3128 KB |
Output is correct |
60 |
Correct |
15 ms |
3164 KB |
Output is correct |
61 |
Correct |
11 ms |
3164 KB |
Output is correct |
62 |
Correct |
7 ms |
3164 KB |
Output is correct |
63 |
Correct |
21 ms |
3184 KB |
Output is correct |
64 |
Correct |
24 ms |
3228 KB |
Output is correct |
65 |
Correct |
25 ms |
3088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
16336 KB |
Output is correct |
2 |
Correct |
54 ms |
17108 KB |
Output is correct |
3 |
Incorrect |
53 ms |
13012 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
3676 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
48 ms |
8672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
50 ms |
8564 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
3676 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2800 KB |
Output is correct |
7 |
Correct |
2 ms |
2648 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 |
3676 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 |
3904 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2808 KB |
Output is correct |
19 |
Correct |
1 ms |
3676 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
2 ms |
2648 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 |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 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 |
2652 KB |
Output is correct |
29 |
Correct |
1 ms |
2652 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 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 |
2652 KB |
Output is correct |
35 |
Correct |
2 ms |
2652 KB |
Output is correct |
36 |
Correct |
8 ms |
2908 KB |
Output is correct |
37 |
Correct |
6 ms |
2908 KB |
Output is correct |
38 |
Correct |
20 ms |
3160 KB |
Output is correct |
39 |
Correct |
29 ms |
3160 KB |
Output is correct |
40 |
Correct |
37 ms |
3156 KB |
Output is correct |
41 |
Correct |
6 ms |
2908 KB |
Output is correct |
42 |
Correct |
6 ms |
3004 KB |
Output is correct |
43 |
Correct |
6 ms |
2904 KB |
Output is correct |
44 |
Correct |
6 ms |
3016 KB |
Output is correct |
45 |
Correct |
6 ms |
3676 KB |
Output is correct |
46 |
Correct |
7 ms |
3676 KB |
Output is correct |
47 |
Correct |
2 ms |
2648 KB |
Output is correct |
48 |
Correct |
7 ms |
2904 KB |
Output is correct |
49 |
Correct |
5 ms |
2908 KB |
Output is correct |
50 |
Correct |
5 ms |
2908 KB |
Output is correct |
51 |
Correct |
28 ms |
3180 KB |
Output is correct |
52 |
Correct |
25 ms |
3152 KB |
Output is correct |
53 |
Correct |
29 ms |
3076 KB |
Output is correct |
54 |
Correct |
30 ms |
3152 KB |
Output is correct |
55 |
Correct |
27 ms |
3164 KB |
Output is correct |
56 |
Correct |
34 ms |
3104 KB |
Output is correct |
57 |
Correct |
26 ms |
3164 KB |
Output is correct |
58 |
Correct |
26 ms |
3272 KB |
Output is correct |
59 |
Correct |
20 ms |
3128 KB |
Output is correct |
60 |
Correct |
15 ms |
3164 KB |
Output is correct |
61 |
Correct |
11 ms |
3164 KB |
Output is correct |
62 |
Correct |
7 ms |
3164 KB |
Output is correct |
63 |
Correct |
21 ms |
3184 KB |
Output is correct |
64 |
Correct |
24 ms |
3228 KB |
Output is correct |
65 |
Correct |
25 ms |
3088 KB |
Output is correct |
66 |
Correct |
2 ms |
2648 KB |
Output is correct |
67 |
Incorrect |
2 ms |
2648 KB |
Output isn't correct |
68 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
3676 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2800 KB |
Output is correct |
7 |
Correct |
2 ms |
2648 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 |
3676 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 |
3904 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2808 KB |
Output is correct |
19 |
Correct |
1 ms |
3676 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
2 ms |
2648 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 |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 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 |
2652 KB |
Output is correct |
29 |
Correct |
1 ms |
2652 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 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 |
2652 KB |
Output is correct |
35 |
Correct |
2 ms |
2652 KB |
Output is correct |
36 |
Correct |
8 ms |
2908 KB |
Output is correct |
37 |
Correct |
6 ms |
2908 KB |
Output is correct |
38 |
Correct |
20 ms |
3160 KB |
Output is correct |
39 |
Correct |
29 ms |
3160 KB |
Output is correct |
40 |
Correct |
37 ms |
3156 KB |
Output is correct |
41 |
Correct |
6 ms |
2908 KB |
Output is correct |
42 |
Correct |
6 ms |
3004 KB |
Output is correct |
43 |
Correct |
6 ms |
2904 KB |
Output is correct |
44 |
Correct |
6 ms |
3016 KB |
Output is correct |
45 |
Correct |
6 ms |
3676 KB |
Output is correct |
46 |
Correct |
7 ms |
3676 KB |
Output is correct |
47 |
Correct |
2 ms |
2648 KB |
Output is correct |
48 |
Correct |
7 ms |
2904 KB |
Output is correct |
49 |
Correct |
5 ms |
2908 KB |
Output is correct |
50 |
Correct |
5 ms |
2908 KB |
Output is correct |
51 |
Correct |
28 ms |
3180 KB |
Output is correct |
52 |
Correct |
25 ms |
3152 KB |
Output is correct |
53 |
Correct |
29 ms |
3076 KB |
Output is correct |
54 |
Correct |
30 ms |
3152 KB |
Output is correct |
55 |
Correct |
27 ms |
3164 KB |
Output is correct |
56 |
Correct |
34 ms |
3104 KB |
Output is correct |
57 |
Correct |
26 ms |
3164 KB |
Output is correct |
58 |
Correct |
26 ms |
3272 KB |
Output is correct |
59 |
Correct |
20 ms |
3128 KB |
Output is correct |
60 |
Correct |
15 ms |
3164 KB |
Output is correct |
61 |
Correct |
11 ms |
3164 KB |
Output is correct |
62 |
Correct |
7 ms |
3164 KB |
Output is correct |
63 |
Correct |
21 ms |
3184 KB |
Output is correct |
64 |
Correct |
24 ms |
3228 KB |
Output is correct |
65 |
Correct |
25 ms |
3088 KB |
Output is correct |
66 |
Correct |
52 ms |
16336 KB |
Output is correct |
67 |
Correct |
54 ms |
17108 KB |
Output is correct |
68 |
Incorrect |
53 ms |
13012 KB |
Output isn't correct |
69 |
Halted |
0 ms |
0 KB |
- |