#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n);
vector<vector<long long>> dp(n, vector<long long>(1 << k));
for (int i = 0; i < n; i++) {
cin >> a[i];
--a[i];
dp[i][1 << a[i]] = 1;
}
vector<vector<int>> g(n);
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
--u, --v;
g[u].push_back(v);
g[v].push_back(u);
}
for (int j = 0; j < (1 << k); j++) {
for (int i = 0; i < n; i++) {
if ((j & (1 << a[i]))) {
continue;
}
for (int x : g[i]) {
if (!(j & (1 << a[x]))) {
continue;
}
dp[i][j ^ (1 << a[i])] += dp[x][j];
}
}
}
long long ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < (1 << k); j++) {
ans += dp[i][j];
}
}
cout << ans - n << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
7428 KB |
Output is correct |
2 |
Correct |
55 ms |
6192 KB |
Output is correct |
3 |
Correct |
261 ms |
51784 KB |
Output is correct |
4 |
Correct |
114 ms |
11076 KB |
Output is correct |
5 |
Correct |
82 ms |
10524 KB |
Output is correct |
6 |
Correct |
200 ms |
37232 KB |
Output is correct |
7 |
Correct |
286 ms |
51844 KB |
Output is correct |
8 |
Correct |
286 ms |
52700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
70 ms |
7428 KB |
Output is correct |
12 |
Correct |
55 ms |
6192 KB |
Output is correct |
13 |
Correct |
261 ms |
51784 KB |
Output is correct |
14 |
Correct |
114 ms |
11076 KB |
Output is correct |
15 |
Correct |
82 ms |
10524 KB |
Output is correct |
16 |
Correct |
200 ms |
37232 KB |
Output is correct |
17 |
Correct |
286 ms |
51844 KB |
Output is correct |
18 |
Correct |
286 ms |
52700 KB |
Output is correct |
19 |
Correct |
67 ms |
7368 KB |
Output is correct |
20 |
Correct |
52 ms |
6104 KB |
Output is correct |
21 |
Correct |
278 ms |
51896 KB |
Output is correct |
22 |
Correct |
92 ms |
10896 KB |
Output is correct |
23 |
Correct |
85 ms |
10464 KB |
Output is correct |
24 |
Correct |
191 ms |
37260 KB |
Output is correct |
25 |
Correct |
263 ms |
51908 KB |
Output is correct |
26 |
Correct |
270 ms |
52504 KB |
Output is correct |
27 |
Correct |
66 ms |
6212 KB |
Output is correct |
28 |
Correct |
91 ms |
9100 KB |
Output is correct |
29 |
Correct |
403 ms |
70768 KB |
Output is correct |
30 |
Correct |
244 ms |
38828 KB |
Output is correct |
31 |
Correct |
249 ms |
38896 KB |
Output is correct |
32 |
Correct |
370 ms |
70760 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
0 ms |
204 KB |
Output is correct |
38 |
Correct |
1 ms |
312 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
0 ms |
332 KB |
Output is correct |
41 |
Correct |
0 ms |
204 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
30 ms |
2280 KB |
Output is correct |
3 |
Correct |
18 ms |
2128 KB |
Output is correct |
4 |
Correct |
64 ms |
17348 KB |
Output is correct |
5 |
Correct |
48 ms |
18060 KB |
Output is correct |
6 |
Correct |
160 ms |
36128 KB |
Output is correct |
7 |
Correct |
24 ms |
2128 KB |
Output is correct |
8 |
Correct |
97 ms |
23528 KB |
Output is correct |
9 |
Correct |
73 ms |
24328 KB |
Output is correct |
10 |
Correct |
97 ms |
24344 KB |
Output is correct |
11 |
Correct |
84 ms |
19012 KB |
Output is correct |
12 |
Correct |
92 ms |
28116 KB |
Output is correct |
13 |
Correct |
86 ms |
19288 KB |
Output is correct |
14 |
Correct |
152 ms |
36040 KB |
Output is correct |
15 |
Correct |
152 ms |
36368 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
0 ms |
336 KB |
Output is correct |
18 |
Correct |
0 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
208 KB |
Output is correct |
20 |
Correct |
0 ms |
316 KB |
Output is correct |
21 |
Correct |
0 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
208 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
208 KB |
Output is correct |
25 |
Correct |
0 ms |
208 KB |
Output is correct |