#include <bits/stdc++.h>
using namespace std;
// #define int long long
signed main(){
int n, m, k;
cin >> n >> m >> k;
vector<int> col(n);
for(int i = 0; i < n; i++) cin >> col[i], col[i]--;
vector<int> adj[n + 5];
for(int i = 0; i < m; i++){
int a, b;
cin >> a >> b;
a--, b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
long long dp[k + 5][n + 5][35];
memset(dp, 0, sizeof dp);
for(int i = 0; i < n; i++) dp[0][i][(1 << col[i])] = 1;
for(int i = 1; i < k; i++){
for(int j = 0; j < n; j++){
for(int x : adj[j]){
for(int mask = 0; mask < (1 << k); mask++){
if(!(mask & (1 << col[j]))){
dp[i][j][mask | (1 << col[j])] += dp[i - 1][x][mask];
}
}
}
}
}
// cout << (1 << k) << endl;
long long ans = 0;
for(int i = 1; i < k; i++){
for(int j = 0; j < n; j++){
for(int mask = 0; mask < (1 << k); mask++){
ans += dp[i][j][mask];
}
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
604 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 |
85 ms |
15084 KB |
Output is correct |
2 |
Correct |
77 ms |
5712 KB |
Output is correct |
3 |
Correct |
490 ms |
674444 KB |
Output is correct |
4 |
Correct |
126 ms |
63056 KB |
Output is correct |
5 |
Correct |
116 ms |
54728 KB |
Output is correct |
6 |
Correct |
391 ms |
451364 KB |
Output is correct |
7 |
Correct |
490 ms |
678996 KB |
Output is correct |
8 |
Correct |
536 ms |
679504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
85 ms |
15084 KB |
Output is correct |
12 |
Correct |
77 ms |
5712 KB |
Output is correct |
13 |
Correct |
490 ms |
674444 KB |
Output is correct |
14 |
Correct |
126 ms |
63056 KB |
Output is correct |
15 |
Correct |
116 ms |
54728 KB |
Output is correct |
16 |
Correct |
391 ms |
451364 KB |
Output is correct |
17 |
Correct |
490 ms |
678996 KB |
Output is correct |
18 |
Correct |
536 ms |
679504 KB |
Output is correct |
19 |
Correct |
87 ms |
17748 KB |
Output is correct |
20 |
Correct |
67 ms |
8016 KB |
Output is correct |
21 |
Correct |
486 ms |
678936 KB |
Output is correct |
22 |
Correct |
129 ms |
66388 KB |
Output is correct |
23 |
Correct |
120 ms |
58136 KB |
Output is correct |
24 |
Correct |
372 ms |
455380 KB |
Output is correct |
25 |
Correct |
486 ms |
678872 KB |
Output is correct |
26 |
Correct |
497 ms |
679504 KB |
Output is correct |
27 |
Correct |
82 ms |
8100 KB |
Output is correct |
28 |
Correct |
112 ms |
27468 KB |
Output is correct |
29 |
Correct |
627 ms |
761172 KB |
Output is correct |
30 |
Correct |
405 ms |
384128 KB |
Output is correct |
31 |
Correct |
403 ms |
384456 KB |
Output is correct |
32 |
Correct |
617 ms |
761172 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
604 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
604 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
604 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
37 ms |
3348 KB |
Output is correct |
3 |
Correct |
23 ms |
3164 KB |
Output is correct |
4 |
Correct |
157 ms |
226368 KB |
Output is correct |
5 |
Correct |
150 ms |
227016 KB |
Output is correct |
6 |
Correct |
265 ms |
281172 KB |
Output is correct |
7 |
Correct |
33 ms |
3412 KB |
Output is correct |
8 |
Correct |
206 ms |
253868 KB |
Output is correct |
9 |
Correct |
174 ms |
254412 KB |
Output is correct |
10 |
Correct |
187 ms |
254412 KB |
Output is correct |
11 |
Correct |
136 ms |
141748 KB |
Output is correct |
12 |
Correct |
181 ms |
211880 KB |
Output is correct |
13 |
Correct |
134 ms |
141756 KB |
Output is correct |
14 |
Correct |
251 ms |
281168 KB |
Output is correct |
15 |
Correct |
264 ms |
281168 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
432 KB |
Output is correct |
19 |
Correct |
0 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
604 KB |
Output is correct |
22 |
Correct |
0 ms |
604 KB |
Output is correct |
23 |
Correct |
0 ms |
604 KB |
Output is correct |
24 |
Correct |
0 ms |
436 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |