#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[300005][1<<5], val[300005];
int main() {
int n, m, k, a, b;
cin >> n >> m >> k;
for(int i=0; i<n; i++) cin >> val[i], val[i]--;
vector<int> graph[n];
for(int i=0; i<m; i++) {
cin >> a >> b;
graph[a-1].push_back(b-1);
graph[b-1].push_back(a-1);
}
for(int i=0; i<n; i++) dp[i][1<<val[i]] = 1;
for(int s=0; s<(1<<k); s++) {
for(int i=0; i<n; i++) {
if((s & (1 << val[i])) == 0) continue;
for(int &j : graph[i]) {
if((s & (1 << val[j])) == 0 || val[j] == val[i]) continue;
dp[i][s] += dp[j][s^(1<<val[i])];
}
}
}
ll ans = 0;
for(int i=0; i<n; i++)
for(int j=0; j<(1<<k); j++)
if(__builtin_popcount(j) > 1) ans += dp[i][j];
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
128 ms |
8924 KB |
Output is correct |
2 |
Correct |
104 ms |
8096 KB |
Output is correct |
3 |
Correct |
357 ms |
97736 KB |
Output is correct |
4 |
Correct |
157 ms |
19264 KB |
Output is correct |
5 |
Correct |
139 ms |
19300 KB |
Output is correct |
6 |
Correct |
247 ms |
69848 KB |
Output is correct |
7 |
Correct |
355 ms |
97572 KB |
Output is correct |
8 |
Correct |
369 ms |
98388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
128 ms |
8924 KB |
Output is correct |
12 |
Correct |
104 ms |
8096 KB |
Output is correct |
13 |
Correct |
357 ms |
97736 KB |
Output is correct |
14 |
Correct |
157 ms |
19264 KB |
Output is correct |
15 |
Correct |
139 ms |
19300 KB |
Output is correct |
16 |
Correct |
247 ms |
69848 KB |
Output is correct |
17 |
Correct |
355 ms |
97572 KB |
Output is correct |
18 |
Correct |
369 ms |
98388 KB |
Output is correct |
19 |
Correct |
151 ms |
9028 KB |
Output is correct |
20 |
Correct |
108 ms |
8088 KB |
Output is correct |
21 |
Correct |
346 ms |
97732 KB |
Output is correct |
22 |
Correct |
152 ms |
19284 KB |
Output is correct |
23 |
Correct |
142 ms |
19284 KB |
Output is correct |
24 |
Correct |
254 ms |
69704 KB |
Output is correct |
25 |
Correct |
344 ms |
97780 KB |
Output is correct |
26 |
Correct |
330 ms |
98424 KB |
Output is correct |
27 |
Correct |
128 ms |
8232 KB |
Output is correct |
28 |
Correct |
147 ms |
12024 KB |
Output is correct |
29 |
Correct |
482 ms |
97724 KB |
Output is correct |
30 |
Correct |
299 ms |
55028 KB |
Output is correct |
31 |
Correct |
298 ms |
54828 KB |
Output is correct |
32 |
Correct |
448 ms |
97612 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2392 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2492 KB |
Output is correct |
42 |
Correct |
1 ms |
2488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
53 ms |
4340 KB |
Output is correct |
3 |
Correct |
35 ms |
4180 KB |
Output is correct |
4 |
Correct |
89 ms |
35668 KB |
Output is correct |
5 |
Correct |
89 ms |
36320 KB |
Output is correct |
6 |
Correct |
154 ms |
35572 KB |
Output is correct |
7 |
Correct |
41 ms |
4180 KB |
Output is correct |
8 |
Correct |
121 ms |
35664 KB |
Output is correct |
9 |
Correct |
96 ms |
36552 KB |
Output is correct |
10 |
Correct |
100 ms |
36432 KB |
Output is correct |
11 |
Correct |
91 ms |
21032 KB |
Output is correct |
12 |
Correct |
118 ms |
28984 KB |
Output is correct |
13 |
Correct |
93 ms |
21128 KB |
Output is correct |
14 |
Correct |
172 ms |
35660 KB |
Output is correct |
15 |
Correct |
164 ms |
36092 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2492 KB |
Output is correct |
24 |
Correct |
1 ms |
2496 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |