#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3e5 + 20;
const int mod = 1e9 + 7;
vector<int> g[maxn], t[maxn];
int dw[maxn], h[maxn], rt[maxn], a[maxn], sz[maxn];
bool visited[maxn];
int sz2[maxn];
ll answer = 0;
void dfs2(int v, int par = -1){
sz2[v] = a[v];
for (auto u : t[v]){
if (u != par){
dfs2(u, v);
sz2[v] += sz2[u];
answer += 1ll * a[v] * sz2[u] * (sz[rt[v]] - sz2[u] - a[v]);
}
}
if (par != -1)
answer += 1ll * a[v] * (sz2[v] - a[v]) * (sz[rt[v]] - sz2[v]);
}
int dfs(int v, int root){
rt[v] = root;
visited[v] = true;
int ret = h[v];
sz[v] = 1;
dw[v] = v;
a[v] = 1;
for (auto u : g[v]){
if (!visited[u]){
h[u] = h[v] + 1;
int k = dfs(u, root);
sz[v] += sz[u];
if (k <= h[v]){
a[v] = a[u];
dw[v] = dw[u];
}
ret = min(ret, k);
}
else if (h[u] < h[v] - 1){
dw[v] = v;
a[v] = h[v] - h[u] + 1;
ret = h[u];
}
}
return ret;
}
int adj[12][12], dp[2000][12];
int main(){
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
if (n <= 10){
for (int i = 1; i <= m; i++){
int v, u;
cin >> v >> u;
v --, u --;
adj[v][u] = adj[u][v] = 1;
}
int answer = 0;
for (int s = 0; s < n; s++){
for (int c = 0; c < n; c++){
if (c == s)
continue;
for (int f = 0; f < n; f++){
if (f == c or f == s)
continue;
memset(dp, 0, sizeof dp);
dp[(1 << s)][s] = 1;
bool found = 0;
for (int mask = (1<<s)+1; mask < (1 << n); mask++){
for (int i = 0; i < n; i++){
if (!(mask & (1 << i)))
continue;
for (int j = 0; j < n; j++)
dp[mask][i] |= (adj[i][j] & dp[mask^(1<<i)][j]);
}
if (mask & (1 << s) and mask & (1 << c) and dp[mask][f])
found = 1;
}
answer += found;
}
}
}
cout << answer << endl;
return 0;
}
for (int i = 0; i < m; i++){
int v, u;
cin >> v >> u;
g[v].push_back(u);
g[u].push_back(v);
}
for (int v = 1; v <= n; v++)
if (!visited[v])
dfs(v, v);
for (int i = 1; i <= n; i++)
for (auto j : g[i])
if (dw[i] != dw[j])
t[dw[i]].push_back(dw[j]);
for (int v = 1; v <= n; v++)
if (h[v] == 0)
dfs2(dw[v]);
for (int c = 1; c <= n; c++){
if (a[dw[c]] == 1)
continue;
int tot = 0;
for (auto u : g[c]){
if (h[u] == h[c]+1 and dw[u] != dw[c]){
answer -= 2ll * (a[dw[c]]-1) * sz[u] * tot;
tot += sz[u];
}
if (h[u] == h[c]-1 and dw[u] != dw[c]){
answer -= 2ll * (a[dw[c]]-1) * (sz[rt[c]] - sz[c]) * tot;
tot += (sz[rt[c]] - sz[c]);
}
}
}
for (int v = 1; v <= n; v++)
if (dw[v] == v and a[v] >= 3)
answer -= 1ll*a[v]*(a[v]-1)*(a[v]-2);
for (int f = 1; f <= n; f++){
if (a[dw[f]] == 1)
continue;
int subsz = 1;
for (auto u : g[f]){
if (h[u] == h[f]+1 and dw[u] != dw[f])
subsz += sz[u];
if (h[u] == h[f]-1 and dw[u] != dw[f])
subsz += (sz[rt[f]] - sz[f]);
}
int outsz = sz[rt[f]] - subsz;
answer += 2ll * (a[dw[f]]-1) * (outsz-1);
}
cout << answer << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14464 KB |
Output is correct |
2 |
Correct |
8 ms |
14464 KB |
Output is correct |
3 |
Correct |
7 ms |
14464 KB |
Output is correct |
4 |
Correct |
8 ms |
14464 KB |
Output is correct |
5 |
Correct |
8 ms |
14464 KB |
Output is correct |
6 |
Correct |
66 ms |
14572 KB |
Output is correct |
7 |
Correct |
73 ms |
14464 KB |
Output is correct |
8 |
Correct |
67 ms |
14568 KB |
Output is correct |
9 |
Correct |
76 ms |
14464 KB |
Output is correct |
10 |
Correct |
64 ms |
14572 KB |
Output is correct |
11 |
Correct |
64 ms |
14464 KB |
Output is correct |
12 |
Correct |
65 ms |
14572 KB |
Output is correct |
13 |
Correct |
64 ms |
14576 KB |
Output is correct |
14 |
Correct |
66 ms |
14464 KB |
Output is correct |
15 |
Correct |
64 ms |
14464 KB |
Output is correct |
16 |
Correct |
64 ms |
14464 KB |
Output is correct |
17 |
Correct |
69 ms |
14464 KB |
Output is correct |
18 |
Correct |
67 ms |
14584 KB |
Output is correct |
19 |
Correct |
65 ms |
14464 KB |
Output is correct |
20 |
Correct |
66 ms |
14464 KB |
Output is correct |
21 |
Correct |
64 ms |
14464 KB |
Output is correct |
22 |
Correct |
64 ms |
14464 KB |
Output is correct |
23 |
Correct |
25 ms |
14464 KB |
Output is correct |
24 |
Correct |
13 ms |
14464 KB |
Output is correct |
25 |
Correct |
26 ms |
14464 KB |
Output is correct |
26 |
Correct |
64 ms |
14464 KB |
Output is correct |
27 |
Correct |
13 ms |
14464 KB |
Output is correct |
28 |
Correct |
26 ms |
14464 KB |
Output is correct |
29 |
Correct |
64 ms |
14464 KB |
Output is correct |
30 |
Correct |
13 ms |
14464 KB |
Output is correct |
31 |
Correct |
28 ms |
14464 KB |
Output is correct |
32 |
Correct |
64 ms |
14464 KB |
Output is correct |
33 |
Correct |
26 ms |
14464 KB |
Output is correct |
34 |
Correct |
26 ms |
14464 KB |
Output is correct |
35 |
Correct |
64 ms |
14464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14464 KB |
Output is correct |
2 |
Correct |
8 ms |
14464 KB |
Output is correct |
3 |
Correct |
7 ms |
14464 KB |
Output is correct |
4 |
Correct |
8 ms |
14464 KB |
Output is correct |
5 |
Correct |
8 ms |
14464 KB |
Output is correct |
6 |
Correct |
66 ms |
14572 KB |
Output is correct |
7 |
Correct |
73 ms |
14464 KB |
Output is correct |
8 |
Correct |
67 ms |
14568 KB |
Output is correct |
9 |
Correct |
76 ms |
14464 KB |
Output is correct |
10 |
Correct |
64 ms |
14572 KB |
Output is correct |
11 |
Correct |
64 ms |
14464 KB |
Output is correct |
12 |
Correct |
65 ms |
14572 KB |
Output is correct |
13 |
Correct |
64 ms |
14576 KB |
Output is correct |
14 |
Correct |
66 ms |
14464 KB |
Output is correct |
15 |
Correct |
64 ms |
14464 KB |
Output is correct |
16 |
Correct |
64 ms |
14464 KB |
Output is correct |
17 |
Correct |
69 ms |
14464 KB |
Output is correct |
18 |
Correct |
67 ms |
14584 KB |
Output is correct |
19 |
Correct |
65 ms |
14464 KB |
Output is correct |
20 |
Correct |
66 ms |
14464 KB |
Output is correct |
21 |
Correct |
64 ms |
14464 KB |
Output is correct |
22 |
Correct |
64 ms |
14464 KB |
Output is correct |
23 |
Correct |
25 ms |
14464 KB |
Output is correct |
24 |
Correct |
13 ms |
14464 KB |
Output is correct |
25 |
Correct |
26 ms |
14464 KB |
Output is correct |
26 |
Correct |
64 ms |
14464 KB |
Output is correct |
27 |
Correct |
13 ms |
14464 KB |
Output is correct |
28 |
Correct |
26 ms |
14464 KB |
Output is correct |
29 |
Correct |
64 ms |
14464 KB |
Output is correct |
30 |
Correct |
13 ms |
14464 KB |
Output is correct |
31 |
Correct |
28 ms |
14464 KB |
Output is correct |
32 |
Correct |
64 ms |
14464 KB |
Output is correct |
33 |
Correct |
26 ms |
14464 KB |
Output is correct |
34 |
Correct |
26 ms |
14464 KB |
Output is correct |
35 |
Correct |
64 ms |
14464 KB |
Output is correct |
36 |
Correct |
7 ms |
14336 KB |
Output is correct |
37 |
Correct |
8 ms |
14464 KB |
Output is correct |
38 |
Runtime error |
644 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
39 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
27516 KB |
Output is correct |
2 |
Correct |
85 ms |
27512 KB |
Output is correct |
3 |
Correct |
89 ms |
25464 KB |
Output is correct |
4 |
Correct |
87 ms |
26744 KB |
Output is correct |
5 |
Correct |
83 ms |
23672 KB |
Output is correct |
6 |
Correct |
105 ms |
24312 KB |
Output is correct |
7 |
Correct |
108 ms |
23544 KB |
Output is correct |
8 |
Correct |
113 ms |
24056 KB |
Output is correct |
9 |
Correct |
115 ms |
22648 KB |
Output is correct |
10 |
Correct |
114 ms |
23160 KB |
Output is correct |
11 |
Correct |
91 ms |
21624 KB |
Output is correct |
12 |
Correct |
104 ms |
21496 KB |
Output is correct |
13 |
Correct |
68 ms |
21628 KB |
Output is correct |
14 |
Correct |
79 ms |
21496 KB |
Output is correct |
15 |
Correct |
61 ms |
21368 KB |
Output is correct |
16 |
Correct |
56 ms |
20984 KB |
Output is correct |
17 |
Correct |
11 ms |
16768 KB |
Output is correct |
18 |
Correct |
11 ms |
16896 KB |
Output is correct |
19 |
Correct |
11 ms |
16768 KB |
Output is correct |
20 |
Correct |
11 ms |
16768 KB |
Output is correct |
21 |
Correct |
10 ms |
16768 KB |
Output is correct |
22 |
Correct |
10 ms |
16768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14616 KB |
Output is correct |
2 |
Correct |
8 ms |
14592 KB |
Output is correct |
3 |
Correct |
9 ms |
14592 KB |
Output is correct |
4 |
Correct |
8 ms |
14592 KB |
Output is correct |
5 |
Correct |
8 ms |
14592 KB |
Output is correct |
6 |
Correct |
9 ms |
14592 KB |
Output is correct |
7 |
Correct |
8 ms |
14592 KB |
Output is correct |
8 |
Correct |
9 ms |
14592 KB |
Output is correct |
9 |
Correct |
8 ms |
14592 KB |
Output is correct |
10 |
Correct |
8 ms |
14592 KB |
Output is correct |
11 |
Correct |
8 ms |
14592 KB |
Output is correct |
12 |
Correct |
8 ms |
14592 KB |
Output is correct |
13 |
Correct |
9 ms |
14592 KB |
Output is correct |
14 |
Correct |
8 ms |
14592 KB |
Output is correct |
15 |
Correct |
8 ms |
14592 KB |
Output is correct |
16 |
Correct |
9 ms |
14592 KB |
Output is correct |
17 |
Correct |
8 ms |
14592 KB |
Output is correct |
18 |
Correct |
8 ms |
14592 KB |
Output is correct |
19 |
Correct |
8 ms |
14592 KB |
Output is correct |
20 |
Correct |
10 ms |
14720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
93 ms |
23416 KB |
Output is correct |
2 |
Correct |
89 ms |
23416 KB |
Output is correct |
3 |
Correct |
83 ms |
23416 KB |
Output is correct |
4 |
Correct |
82 ms |
23420 KB |
Output is correct |
5 |
Correct |
83 ms |
23416 KB |
Output is correct |
6 |
Correct |
104 ms |
27512 KB |
Output is correct |
7 |
Correct |
98 ms |
25980 KB |
Output is correct |
8 |
Correct |
95 ms |
25288 KB |
Output is correct |
9 |
Correct |
92 ms |
24572 KB |
Output is correct |
10 |
Correct |
96 ms |
23416 KB |
Output is correct |
11 |
Correct |
83 ms |
23416 KB |
Output is correct |
12 |
Correct |
82 ms |
23416 KB |
Output is correct |
13 |
Correct |
81 ms |
23416 KB |
Output is correct |
14 |
Correct |
75 ms |
23164 KB |
Output is correct |
15 |
Correct |
70 ms |
22904 KB |
Output is correct |
16 |
Correct |
48 ms |
21624 KB |
Output is correct |
17 |
Correct |
60 ms |
24036 KB |
Output is correct |
18 |
Correct |
61 ms |
23920 KB |
Output is correct |
19 |
Correct |
59 ms |
24044 KB |
Output is correct |
20 |
Correct |
61 ms |
23928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14592 KB |
Output is correct |
2 |
Correct |
8 ms |
14592 KB |
Output is correct |
3 |
Correct |
12 ms |
14592 KB |
Output is correct |
4 |
Correct |
12 ms |
14592 KB |
Output is correct |
5 |
Correct |
12 ms |
14592 KB |
Output is correct |
6 |
Correct |
8 ms |
14592 KB |
Output is correct |
7 |
Correct |
9 ms |
14592 KB |
Output is correct |
8 |
Correct |
9 ms |
14592 KB |
Output is correct |
9 |
Correct |
11 ms |
14592 KB |
Output is correct |
10 |
Correct |
8 ms |
14592 KB |
Output is correct |
11 |
Correct |
9 ms |
14592 KB |
Output is correct |
12 |
Correct |
9 ms |
14592 KB |
Output is correct |
13 |
Correct |
9 ms |
14592 KB |
Output is correct |
14 |
Correct |
8 ms |
14592 KB |
Output is correct |
15 |
Correct |
8 ms |
14592 KB |
Output is correct |
16 |
Correct |
8 ms |
14592 KB |
Output is correct |
17 |
Correct |
8 ms |
14592 KB |
Output is correct |
18 |
Correct |
9 ms |
14592 KB |
Output is correct |
19 |
Correct |
8 ms |
14592 KB |
Output is correct |
20 |
Correct |
8 ms |
14592 KB |
Output is correct |
21 |
Correct |
9 ms |
14592 KB |
Output is correct |
22 |
Correct |
9 ms |
14592 KB |
Output is correct |
23 |
Correct |
8 ms |
14592 KB |
Output is correct |
24 |
Correct |
9 ms |
14592 KB |
Output is correct |
25 |
Correct |
8 ms |
14464 KB |
Output is correct |
26 |
Correct |
8 ms |
14464 KB |
Output is correct |
27 |
Correct |
11 ms |
14464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
23416 KB |
Output is correct |
2 |
Correct |
96 ms |
23280 KB |
Output is correct |
3 |
Correct |
97 ms |
22264 KB |
Output is correct |
4 |
Correct |
134 ms |
23032 KB |
Output is correct |
5 |
Correct |
112 ms |
22136 KB |
Output is correct |
6 |
Correct |
89 ms |
21888 KB |
Output is correct |
7 |
Correct |
83 ms |
21752 KB |
Output is correct |
8 |
Correct |
76 ms |
21624 KB |
Output is correct |
9 |
Correct |
83 ms |
21616 KB |
Output is correct |
10 |
Correct |
73 ms |
21496 KB |
Output is correct |
11 |
Correct |
74 ms |
21496 KB |
Output is correct |
12 |
Correct |
73 ms |
21496 KB |
Output is correct |
13 |
Correct |
84 ms |
21528 KB |
Output is correct |
14 |
Correct |
94 ms |
23032 KB |
Output is correct |
15 |
Correct |
108 ms |
26744 KB |
Output is correct |
16 |
Correct |
104 ms |
25720 KB |
Output is correct |
17 |
Correct |
102 ms |
26104 KB |
Output is correct |
18 |
Correct |
107 ms |
25212 KB |
Output is correct |
19 |
Correct |
98 ms |
22904 KB |
Output is correct |
20 |
Correct |
111 ms |
22868 KB |
Output is correct |
21 |
Correct |
94 ms |
22904 KB |
Output is correct |
22 |
Correct |
89 ms |
22648 KB |
Output is correct |
23 |
Correct |
88 ms |
22136 KB |
Output is correct |
24 |
Correct |
86 ms |
24056 KB |
Output is correct |
25 |
Correct |
90 ms |
24056 KB |
Output is correct |
26 |
Correct |
84 ms |
23412 KB |
Output is correct |
27 |
Correct |
91 ms |
23416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14464 KB |
Output is correct |
2 |
Correct |
8 ms |
14464 KB |
Output is correct |
3 |
Correct |
7 ms |
14464 KB |
Output is correct |
4 |
Correct |
8 ms |
14464 KB |
Output is correct |
5 |
Correct |
8 ms |
14464 KB |
Output is correct |
6 |
Correct |
66 ms |
14572 KB |
Output is correct |
7 |
Correct |
73 ms |
14464 KB |
Output is correct |
8 |
Correct |
67 ms |
14568 KB |
Output is correct |
9 |
Correct |
76 ms |
14464 KB |
Output is correct |
10 |
Correct |
64 ms |
14572 KB |
Output is correct |
11 |
Correct |
64 ms |
14464 KB |
Output is correct |
12 |
Correct |
65 ms |
14572 KB |
Output is correct |
13 |
Correct |
64 ms |
14576 KB |
Output is correct |
14 |
Correct |
66 ms |
14464 KB |
Output is correct |
15 |
Correct |
64 ms |
14464 KB |
Output is correct |
16 |
Correct |
64 ms |
14464 KB |
Output is correct |
17 |
Correct |
69 ms |
14464 KB |
Output is correct |
18 |
Correct |
67 ms |
14584 KB |
Output is correct |
19 |
Correct |
65 ms |
14464 KB |
Output is correct |
20 |
Correct |
66 ms |
14464 KB |
Output is correct |
21 |
Correct |
64 ms |
14464 KB |
Output is correct |
22 |
Correct |
64 ms |
14464 KB |
Output is correct |
23 |
Correct |
25 ms |
14464 KB |
Output is correct |
24 |
Correct |
13 ms |
14464 KB |
Output is correct |
25 |
Correct |
26 ms |
14464 KB |
Output is correct |
26 |
Correct |
64 ms |
14464 KB |
Output is correct |
27 |
Correct |
13 ms |
14464 KB |
Output is correct |
28 |
Correct |
26 ms |
14464 KB |
Output is correct |
29 |
Correct |
64 ms |
14464 KB |
Output is correct |
30 |
Correct |
13 ms |
14464 KB |
Output is correct |
31 |
Correct |
28 ms |
14464 KB |
Output is correct |
32 |
Correct |
64 ms |
14464 KB |
Output is correct |
33 |
Correct |
26 ms |
14464 KB |
Output is correct |
34 |
Correct |
26 ms |
14464 KB |
Output is correct |
35 |
Correct |
64 ms |
14464 KB |
Output is correct |
36 |
Correct |
7 ms |
14336 KB |
Output is correct |
37 |
Correct |
8 ms |
14464 KB |
Output is correct |
38 |
Runtime error |
644 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
39 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14464 KB |
Output is correct |
2 |
Correct |
8 ms |
14464 KB |
Output is correct |
3 |
Correct |
7 ms |
14464 KB |
Output is correct |
4 |
Correct |
8 ms |
14464 KB |
Output is correct |
5 |
Correct |
8 ms |
14464 KB |
Output is correct |
6 |
Correct |
66 ms |
14572 KB |
Output is correct |
7 |
Correct |
73 ms |
14464 KB |
Output is correct |
8 |
Correct |
67 ms |
14568 KB |
Output is correct |
9 |
Correct |
76 ms |
14464 KB |
Output is correct |
10 |
Correct |
64 ms |
14572 KB |
Output is correct |
11 |
Correct |
64 ms |
14464 KB |
Output is correct |
12 |
Correct |
65 ms |
14572 KB |
Output is correct |
13 |
Correct |
64 ms |
14576 KB |
Output is correct |
14 |
Correct |
66 ms |
14464 KB |
Output is correct |
15 |
Correct |
64 ms |
14464 KB |
Output is correct |
16 |
Correct |
64 ms |
14464 KB |
Output is correct |
17 |
Correct |
69 ms |
14464 KB |
Output is correct |
18 |
Correct |
67 ms |
14584 KB |
Output is correct |
19 |
Correct |
65 ms |
14464 KB |
Output is correct |
20 |
Correct |
66 ms |
14464 KB |
Output is correct |
21 |
Correct |
64 ms |
14464 KB |
Output is correct |
22 |
Correct |
64 ms |
14464 KB |
Output is correct |
23 |
Correct |
25 ms |
14464 KB |
Output is correct |
24 |
Correct |
13 ms |
14464 KB |
Output is correct |
25 |
Correct |
26 ms |
14464 KB |
Output is correct |
26 |
Correct |
64 ms |
14464 KB |
Output is correct |
27 |
Correct |
13 ms |
14464 KB |
Output is correct |
28 |
Correct |
26 ms |
14464 KB |
Output is correct |
29 |
Correct |
64 ms |
14464 KB |
Output is correct |
30 |
Correct |
13 ms |
14464 KB |
Output is correct |
31 |
Correct |
28 ms |
14464 KB |
Output is correct |
32 |
Correct |
64 ms |
14464 KB |
Output is correct |
33 |
Correct |
26 ms |
14464 KB |
Output is correct |
34 |
Correct |
26 ms |
14464 KB |
Output is correct |
35 |
Correct |
64 ms |
14464 KB |
Output is correct |
36 |
Correct |
7 ms |
14336 KB |
Output is correct |
37 |
Correct |
8 ms |
14464 KB |
Output is correct |
38 |
Runtime error |
644 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
39 |
Halted |
0 ms |
0 KB |
- |