#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, m, k, color[300300], ans, dp[300300][32];
vector<int> vc[300300];
int32_t main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> m >> k;
for(int i = 1; i <= n; ++i) cin >> color[i], color[i]--;
for(int i = 0; i < m; ++i){
int u, v; cin >> u >> v;
vc[u].push_back(v), vc[v].push_back(u);
}
for(int i = 1; i <= n; ++i) dp[i][(1<<color[i])] = 1;
for(int mask = 0; mask < (1<<k); ++mask){
for(int i = 1; i <= n; ++i){
for(auto v:vc[i]){
if(!(mask&(1<<color[v]))) dp[v][mask|(1<<color[v])] += dp[i][mask];
}
}
}
int ans = 0;
for(int i = 1; i <= n; ++i) for(int j = 0; j < (1<<k); ++j) ans += dp[i][j];
cout << ans - n;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10832 KB |
Output is correct |
2 |
Correct |
2 ms |
10832 KB |
Output is correct |
3 |
Correct |
2 ms |
10832 KB |
Output is correct |
4 |
Correct |
2 ms |
10832 KB |
Output is correct |
5 |
Correct |
2 ms |
10904 KB |
Output is correct |
6 |
Correct |
2 ms |
10832 KB |
Output is correct |
7 |
Correct |
2 ms |
10832 KB |
Output is correct |
8 |
Correct |
3 ms |
10832 KB |
Output is correct |
9 |
Correct |
2 ms |
10832 KB |
Output is correct |
10 |
Correct |
2 ms |
10832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
20808 KB |
Output is correct |
2 |
Correct |
51 ms |
20304 KB |
Output is correct |
3 |
Correct |
241 ms |
99972 KB |
Output is correct |
4 |
Correct |
71 ms |
30536 KB |
Output is correct |
5 |
Correct |
64 ms |
30536 KB |
Output is correct |
6 |
Correct |
154 ms |
73400 KB |
Output is correct |
7 |
Correct |
216 ms |
100168 KB |
Output is correct |
8 |
Correct |
220 ms |
100512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10832 KB |
Output is correct |
2 |
Correct |
2 ms |
10832 KB |
Output is correct |
3 |
Correct |
2 ms |
10832 KB |
Output is correct |
4 |
Correct |
2 ms |
10832 KB |
Output is correct |
5 |
Correct |
2 ms |
10904 KB |
Output is correct |
6 |
Correct |
2 ms |
10832 KB |
Output is correct |
7 |
Correct |
2 ms |
10832 KB |
Output is correct |
8 |
Correct |
3 ms |
10832 KB |
Output is correct |
9 |
Correct |
2 ms |
10832 KB |
Output is correct |
10 |
Correct |
2 ms |
10832 KB |
Output is correct |
11 |
Correct |
63 ms |
20808 KB |
Output is correct |
12 |
Correct |
51 ms |
20304 KB |
Output is correct |
13 |
Correct |
241 ms |
99972 KB |
Output is correct |
14 |
Correct |
71 ms |
30536 KB |
Output is correct |
15 |
Correct |
64 ms |
30536 KB |
Output is correct |
16 |
Correct |
154 ms |
73400 KB |
Output is correct |
17 |
Correct |
216 ms |
100168 KB |
Output is correct |
18 |
Correct |
220 ms |
100512 KB |
Output is correct |
19 |
Correct |
66 ms |
20824 KB |
Output is correct |
20 |
Correct |
60 ms |
20128 KB |
Output is correct |
21 |
Correct |
207 ms |
99868 KB |
Output is correct |
22 |
Correct |
75 ms |
30536 KB |
Output is correct |
23 |
Correct |
63 ms |
30580 KB |
Output is correct |
24 |
Correct |
147 ms |
73528 KB |
Output is correct |
25 |
Correct |
235 ms |
99932 KB |
Output is correct |
26 |
Correct |
217 ms |
100608 KB |
Output is correct |
27 |
Correct |
88 ms |
20040 KB |
Output is correct |
28 |
Correct |
92 ms |
24392 KB |
Output is correct |
29 |
Correct |
299 ms |
100072 KB |
Output is correct |
30 |
Correct |
197 ms |
61368 KB |
Output is correct |
31 |
Correct |
204 ms |
60432 KB |
Output is correct |
32 |
Correct |
310 ms |
99912 KB |
Output is correct |
33 |
Correct |
3 ms |
11088 KB |
Output is correct |
34 |
Correct |
2 ms |
10832 KB |
Output is correct |
35 |
Correct |
2 ms |
10832 KB |
Output is correct |
36 |
Correct |
2 ms |
10832 KB |
Output is correct |
37 |
Correct |
2 ms |
10904 KB |
Output is correct |
38 |
Correct |
3 ms |
10832 KB |
Output is correct |
39 |
Correct |
2 ms |
10832 KB |
Output is correct |
40 |
Correct |
2 ms |
10832 KB |
Output is correct |
41 |
Correct |
3 ms |
10832 KB |
Output is correct |
42 |
Correct |
2 ms |
10832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10832 KB |
Output is correct |
2 |
Correct |
39 ms |
13692 KB |
Output is correct |
3 |
Correct |
19 ms |
13968 KB |
Output is correct |
4 |
Correct |
53 ms |
40368 KB |
Output is correct |
5 |
Correct |
40 ms |
40588 KB |
Output is correct |
6 |
Correct |
113 ms |
40264 KB |
Output is correct |
7 |
Correct |
25 ms |
13792 KB |
Output is correct |
8 |
Correct |
81 ms |
40192 KB |
Output is correct |
9 |
Correct |
47 ms |
40644 KB |
Output is correct |
10 |
Correct |
75 ms |
40476 KB |
Output is correct |
11 |
Correct |
66 ms |
26824 KB |
Output is correct |
12 |
Correct |
70 ms |
33600 KB |
Output is correct |
13 |
Correct |
80 ms |
27008 KB |
Output is correct |
14 |
Correct |
112 ms |
40384 KB |
Output is correct |
15 |
Correct |
113 ms |
40248 KB |
Output is correct |
16 |
Correct |
3 ms |
10832 KB |
Output is correct |
17 |
Correct |
2 ms |
10832 KB |
Output is correct |
18 |
Correct |
3 ms |
10832 KB |
Output is correct |
19 |
Correct |
2 ms |
10832 KB |
Output is correct |
20 |
Correct |
2 ms |
10832 KB |
Output is correct |
21 |
Correct |
3 ms |
10832 KB |
Output is correct |
22 |
Correct |
3 ms |
11004 KB |
Output is correct |
23 |
Correct |
3 ms |
10832 KB |
Output is correct |
24 |
Correct |
2 ms |
10832 KB |
Output is correct |
25 |
Correct |
2 ms |
10832 KB |
Output is correct |