#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << ' ' <<
#define nl << '\n'
vector<vector<int>> g;
signed main(){
cin.tie(0)->sync_with_stdio(0);
int n, m, k, x, y; cin >> n >> m >> k;
int c[n];
for(int i=0; i<n; ++i) cin >> c[i], c[i] = (1<<(c[i]-1));
g.resize(n);
while(m--){
cin >> x >> y; --x, --y;
g[x].push_back(y);
g[y].push_back(x);
}
int ans = 0;
int dp[n][1<<k];
for(int i=0; i<n; ++i){
fill(dp[i], dp[i]+(1<<k), 0LL);
dp[i][c[i]] = 1;
}
for(int cnt=1; cnt<k; ++cnt){
for(int u=0; u<n; ++u) for(int v : g[u]){
for(int i=0; i<(1<<k); ++i){
if(i&c[u]) continue;
int s=0;
for(int j=0; j<k; ++j)
if(i&(1<<j)) ++s;
if(s!=cnt) continue;
dp[u][c[u]|i] += dp[v][i];
ans += dp[v][i];
}
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
10988 KB |
Output is correct |
2 |
Correct |
81 ms |
9836 KB |
Output is correct |
3 |
Correct |
445 ms |
43628 KB |
Output is correct |
4 |
Correct |
122 ms |
13676 KB |
Output is correct |
5 |
Correct |
115 ms |
13292 KB |
Output is correct |
6 |
Correct |
313 ms |
32092 KB |
Output is correct |
7 |
Correct |
430 ms |
43500 KB |
Output is correct |
8 |
Correct |
420 ms |
44012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
97 ms |
10988 KB |
Output is correct |
12 |
Correct |
81 ms |
9836 KB |
Output is correct |
13 |
Correct |
445 ms |
43628 KB |
Output is correct |
14 |
Correct |
122 ms |
13676 KB |
Output is correct |
15 |
Correct |
115 ms |
13292 KB |
Output is correct |
16 |
Correct |
313 ms |
32092 KB |
Output is correct |
17 |
Correct |
430 ms |
43500 KB |
Output is correct |
18 |
Correct |
420 ms |
44012 KB |
Output is correct |
19 |
Correct |
103 ms |
10788 KB |
Output is correct |
20 |
Correct |
80 ms |
9836 KB |
Output is correct |
21 |
Correct |
415 ms |
43628 KB |
Output is correct |
22 |
Correct |
116 ms |
13676 KB |
Output is correct |
23 |
Correct |
107 ms |
13276 KB |
Output is correct |
24 |
Correct |
301 ms |
32092 KB |
Output is correct |
25 |
Correct |
413 ms |
43628 KB |
Output is correct |
26 |
Correct |
420 ms |
44268 KB |
Output is correct |
27 |
Correct |
138 ms |
9836 KB |
Output is correct |
28 |
Correct |
167 ms |
13036 KB |
Output is correct |
29 |
Correct |
601 ms |
62360 KB |
Output is correct |
30 |
Correct |
432 ms |
36572 KB |
Output is correct |
31 |
Correct |
440 ms |
36640 KB |
Output is correct |
32 |
Correct |
596 ms |
62296 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
2 ms |
364 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
1 ms |
364 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
1 ms |
364 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
104 ms |
3436 KB |
Output is correct |
3 |
Correct |
28 ms |
3308 KB |
Output is correct |
4 |
Correct |
97 ms |
14572 KB |
Output is correct |
5 |
Correct |
77 ms |
15072 KB |
Output is correct |
6 |
Correct |
278 ms |
33388 KB |
Output is correct |
7 |
Correct |
45 ms |
3308 KB |
Output is correct |
8 |
Correct |
155 ms |
20844 KB |
Output is correct |
9 |
Correct |
118 ms |
21216 KB |
Output is correct |
10 |
Correct |
139 ms |
20960 KB |
Output is correct |
11 |
Correct |
187 ms |
18148 KB |
Output is correct |
12 |
Correct |
197 ms |
25948 KB |
Output is correct |
13 |
Correct |
200 ms |
18268 KB |
Output is correct |
14 |
Correct |
275 ms |
33388 KB |
Output is correct |
15 |
Correct |
279 ms |
33516 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |