//#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2", "popcnt")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll inf = 1e18;
vector<int> col_v;
vector<vector<int>> g;
ll ans;
int main() {
srand(time(0));
cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, m, k;
cin >> n >> m >> k;
col_v.assign(n + 1, 0);
g.assign(n + 1, {});
for (int i = 1; i <= n; i++) cin >> col_v[i];
for (int i = 1; i <= n; i++) col_v[i] = 1 << (col_v[i] - 1);
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
g[u].emplace_back(v);
g[v].emplace_back(u);
}
vector dp(1 << k, vector(n + 1, 0ll));
for (int i = 1; i <= n; i++) dp[col_v[i]][i] = 1;
for (int bt = 1; bt < (1 << k); bt++) {
for (int u = 1; u <= n; u++) {
for (int v: g[u]) {
if (bt & col_v[v]) continue;
dp[bt | col_v[v]][v] += dp[bt][u];
}
}
if (__builtin_popcount(bt) == 1) continue;
for (int u = 1; u <= n; u++) ans += dp[bt][u];
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
456 KB |
Output is correct |
4 |
Correct |
1 ms |
504 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
360 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
4572 KB |
Output is correct |
2 |
Correct |
47 ms |
6224 KB |
Output is correct |
3 |
Correct |
186 ms |
42576 KB |
Output is correct |
4 |
Correct |
64 ms |
10184 KB |
Output is correct |
5 |
Correct |
58 ms |
9528 KB |
Output is correct |
6 |
Correct |
139 ms |
31088 KB |
Output is correct |
7 |
Correct |
196 ms |
42428 KB |
Output is correct |
8 |
Correct |
197 ms |
43276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
456 KB |
Output is correct |
4 |
Correct |
1 ms |
504 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
360 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
54 ms |
4572 KB |
Output is correct |
12 |
Correct |
47 ms |
6224 KB |
Output is correct |
13 |
Correct |
186 ms |
42576 KB |
Output is correct |
14 |
Correct |
64 ms |
10184 KB |
Output is correct |
15 |
Correct |
58 ms |
9528 KB |
Output is correct |
16 |
Correct |
139 ms |
31088 KB |
Output is correct |
17 |
Correct |
196 ms |
42428 KB |
Output is correct |
18 |
Correct |
197 ms |
43276 KB |
Output is correct |
19 |
Correct |
56 ms |
7248 KB |
Output is correct |
20 |
Correct |
48 ms |
6236 KB |
Output is correct |
21 |
Correct |
193 ms |
42576 KB |
Output is correct |
22 |
Correct |
86 ms |
10048 KB |
Output is correct |
23 |
Correct |
58 ms |
9548 KB |
Output is correct |
24 |
Correct |
119 ms |
31172 KB |
Output is correct |
25 |
Correct |
211 ms |
42576 KB |
Output is correct |
26 |
Correct |
203 ms |
43376 KB |
Output is correct |
27 |
Correct |
66 ms |
6236 KB |
Output is correct |
28 |
Correct |
83 ms |
9236 KB |
Output is correct |
29 |
Correct |
347 ms |
61264 KB |
Output is correct |
30 |
Correct |
168 ms |
34244 KB |
Output is correct |
31 |
Correct |
183 ms |
34364 KB |
Output is correct |
32 |
Correct |
323 ms |
61264 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
344 KB |
Output is correct |
37 |
Correct |
0 ms |
456 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
39 ms |
1696 KB |
Output is correct |
3 |
Correct |
16 ms |
2140 KB |
Output is correct |
4 |
Correct |
45 ms |
14172 KB |
Output is correct |
5 |
Correct |
35 ms |
14920 KB |
Output is correct |
6 |
Correct |
139 ms |
33052 KB |
Output is correct |
7 |
Correct |
23 ms |
2140 KB |
Output is correct |
8 |
Correct |
66 ms |
20564 KB |
Output is correct |
9 |
Correct |
50 ms |
21232 KB |
Output is correct |
10 |
Correct |
56 ms |
21136 KB |
Output is correct |
11 |
Correct |
69 ms |
17624 KB |
Output is correct |
12 |
Correct |
69 ms |
25936 KB |
Output is correct |
13 |
Correct |
74 ms |
17892 KB |
Output is correct |
14 |
Correct |
121 ms |
33156 KB |
Output is correct |
15 |
Correct |
119 ms |
33228 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
600 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |