#include<bits/stdc++.h>
using namespace std;
#define int long long
#define maxn 300005
int n,m,k,dp[maxn][(1<<5)+5],c[maxn];
vector<int> ms[10],edge[maxn];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
cin >> n >> m >> k;
for(int i=1;i<=n;i++){cin >> c[i];c[i]--;dp[i][(1<<c[i])]=1;}
for(int i=1;i<=m;i++){
int u,v;cin >> u >> v;
edge[u].push_back(v);
edge[v].push_back(u);
}
for(int mask=0;mask<(1<<k);mask++){
int cnt=0;
for(int j=0;j<k;j++) cnt+=(mask>>j)&1;
ms[cnt].push_back(mask);
}
int ans=0;
for(int i=2;i<=k;i++){
for(int mask:ms[i]){
for(int j=1;j<=n;j++){
if((mask^(1<<c[j]))==0) continue;
for(int v:edge[j]) dp[j][mask]+=dp[v][mask^(1<<c[j])];
ans+=dp[j][mask];
}
}
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7376 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7376 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
5 ms |
7372 KB |
Output is correct |
8 |
Correct |
4 ms |
7380 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Correct |
4 ms |
7380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
18796 KB |
Output is correct |
2 |
Correct |
50 ms |
17020 KB |
Output is correct |
3 |
Correct |
277 ms |
111544 KB |
Output is correct |
4 |
Correct |
93 ms |
27684 KB |
Output is correct |
5 |
Correct |
114 ms |
27704 KB |
Output is correct |
6 |
Correct |
194 ms |
79920 KB |
Output is correct |
7 |
Correct |
263 ms |
111692 KB |
Output is correct |
8 |
Correct |
290 ms |
112068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7376 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7376 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
5 ms |
7372 KB |
Output is correct |
8 |
Correct |
4 ms |
7380 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Correct |
4 ms |
7380 KB |
Output is correct |
11 |
Correct |
67 ms |
18796 KB |
Output is correct |
12 |
Correct |
50 ms |
17020 KB |
Output is correct |
13 |
Correct |
277 ms |
111544 KB |
Output is correct |
14 |
Correct |
93 ms |
27684 KB |
Output is correct |
15 |
Correct |
114 ms |
27704 KB |
Output is correct |
16 |
Correct |
194 ms |
79920 KB |
Output is correct |
17 |
Correct |
263 ms |
111692 KB |
Output is correct |
18 |
Correct |
290 ms |
112068 KB |
Output is correct |
19 |
Correct |
67 ms |
18836 KB |
Output is correct |
20 |
Correct |
54 ms |
16956 KB |
Output is correct |
21 |
Correct |
279 ms |
111580 KB |
Output is correct |
22 |
Correct |
110 ms |
27696 KB |
Output is correct |
23 |
Correct |
105 ms |
27692 KB |
Output is correct |
24 |
Correct |
191 ms |
79704 KB |
Output is correct |
25 |
Correct |
282 ms |
111700 KB |
Output is correct |
26 |
Correct |
268 ms |
112068 KB |
Output is correct |
27 |
Correct |
58 ms |
16972 KB |
Output is correct |
28 |
Correct |
92 ms |
21216 KB |
Output is correct |
29 |
Correct |
399 ms |
111616 KB |
Output is correct |
30 |
Correct |
276 ms |
64816 KB |
Output is correct |
31 |
Correct |
256 ms |
64868 KB |
Output is correct |
32 |
Correct |
373 ms |
111604 KB |
Output is correct |
33 |
Correct |
4 ms |
7380 KB |
Output is correct |
34 |
Correct |
4 ms |
7380 KB |
Output is correct |
35 |
Correct |
4 ms |
7380 KB |
Output is correct |
36 |
Correct |
4 ms |
7380 KB |
Output is correct |
37 |
Correct |
4 ms |
7380 KB |
Output is correct |
38 |
Correct |
4 ms |
7380 KB |
Output is correct |
39 |
Correct |
4 ms |
7380 KB |
Output is correct |
40 |
Correct |
5 ms |
7380 KB |
Output is correct |
41 |
Correct |
4 ms |
7380 KB |
Output is correct |
42 |
Correct |
4 ms |
7380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
25 ms |
10416 KB |
Output is correct |
3 |
Correct |
20 ms |
10464 KB |
Output is correct |
4 |
Correct |
78 ms |
41840 KB |
Output is correct |
5 |
Correct |
60 ms |
42368 KB |
Output is correct |
6 |
Correct |
182 ms |
41880 KB |
Output is correct |
7 |
Correct |
21 ms |
10324 KB |
Output is correct |
8 |
Correct |
106 ms |
41932 KB |
Output is correct |
9 |
Correct |
78 ms |
42396 KB |
Output is correct |
10 |
Correct |
94 ms |
42520 KB |
Output is correct |
11 |
Correct |
106 ms |
25924 KB |
Output is correct |
12 |
Correct |
109 ms |
34128 KB |
Output is correct |
13 |
Correct |
99 ms |
26284 KB |
Output is correct |
14 |
Correct |
171 ms |
41884 KB |
Output is correct |
15 |
Correct |
177 ms |
42136 KB |
Output is correct |
16 |
Correct |
4 ms |
7380 KB |
Output is correct |
17 |
Correct |
4 ms |
7380 KB |
Output is correct |
18 |
Correct |
4 ms |
7380 KB |
Output is correct |
19 |
Correct |
4 ms |
7380 KB |
Output is correct |
20 |
Correct |
4 ms |
7280 KB |
Output is correct |
21 |
Correct |
5 ms |
7380 KB |
Output is correct |
22 |
Correct |
4 ms |
7380 KB |
Output is correct |
23 |
Correct |
4 ms |
7356 KB |
Output is correct |
24 |
Correct |
4 ms |
7380 KB |
Output is correct |
25 |
Correct |
4 ms |
7380 KB |
Output is correct |