#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define endl '\n'
#define fi first
#define se second
#define For(i, l, r) for (auto i = (l); i < (r); i++)
#define ForE(i, l, r) for (auto i = (l); i <= (r); i++)
#define FordE(i, l, r) for (auto i = (l); i >= (r); i--)
#define Fora(v, a) for (auto v: (a))
#define bend(a) (a).begin(), (a).end()
#define isz(a) ((signed)(a).size())
using ll = long long;
using ld = long double;
using pii = pair <int, int>;
using vi = vector <int>;
using vpii = vector <pii>;
using vvi = vector <vi>;
const int N = 3e5 + 5, K = 5;
int n, m, k;
int a[N];
vi adj[N];
ll dp[N][1 << K];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("KEK.inp", "r", stdin);
// freopen("KEK.out", "w", stdout);
cin >> n >> m >> k;
ForE(u, 1, n){
cin >> a[u]; a[u]--;
}
ForE(i, 1, m){
int u, v; cin >> u >> v;
adj[u].emplace_back(v);
adj[v].emplace_back(u);
}
ForE(u, 1, n){
dp[u][1 << a[u]] = 1;
}
For(msk, 1, (1 << k)){
ForE(u, 1, n){
Fora(v, adj[u]){
if (!(msk >> a[v] & 1)){
dp[v][msk | (1 << a[v])] += dp[u][msk];
}
}
}
}
ll ans = 0;
For(msk, 1, (1 << k)){
if (__builtin_popcount(msk) == 1){
continue;
}
ForE(u, 1, n){
ans += dp[u][msk];
}
}
cout << ans << endl;
}
/*
==================================================+
INPUT: |
--------------------------------------------------|
--------------------------------------------------|
==================================================+
OUTPUT: |
--------------------------------------------------|
--------------------------------------------------|
==================================================+
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
5 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7472 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
4 ms |
7380 KB |
Output is correct |
8 |
Correct |
5 ms |
7376 KB |
Output is correct |
9 |
Correct |
4 ms |
7376 KB |
Output is correct |
10 |
Correct |
4 ms |
7296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
15052 KB |
Output is correct |
2 |
Correct |
77 ms |
13372 KB |
Output is correct |
3 |
Correct |
417 ms |
96644 KB |
Output is correct |
4 |
Correct |
115 ms |
22768 KB |
Output is correct |
5 |
Correct |
87 ms |
22764 KB |
Output is correct |
6 |
Correct |
302 ms |
69360 KB |
Output is correct |
7 |
Correct |
403 ms |
96508 KB |
Output is correct |
8 |
Correct |
418 ms |
97052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
5 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7472 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
4 ms |
7380 KB |
Output is correct |
8 |
Correct |
5 ms |
7376 KB |
Output is correct |
9 |
Correct |
4 ms |
7376 KB |
Output is correct |
10 |
Correct |
4 ms |
7296 KB |
Output is correct |
11 |
Correct |
105 ms |
15052 KB |
Output is correct |
12 |
Correct |
77 ms |
13372 KB |
Output is correct |
13 |
Correct |
417 ms |
96644 KB |
Output is correct |
14 |
Correct |
115 ms |
22768 KB |
Output is correct |
15 |
Correct |
87 ms |
22764 KB |
Output is correct |
16 |
Correct |
302 ms |
69360 KB |
Output is correct |
17 |
Correct |
403 ms |
96508 KB |
Output is correct |
18 |
Correct |
418 ms |
97052 KB |
Output is correct |
19 |
Correct |
90 ms |
15108 KB |
Output is correct |
20 |
Correct |
84 ms |
13400 KB |
Output is correct |
21 |
Correct |
419 ms |
96516 KB |
Output is correct |
22 |
Correct |
121 ms |
22744 KB |
Output is correct |
23 |
Correct |
92 ms |
22700 KB |
Output is correct |
24 |
Correct |
301 ms |
69324 KB |
Output is correct |
25 |
Correct |
414 ms |
96524 KB |
Output is correct |
26 |
Correct |
456 ms |
97164 KB |
Output is correct |
27 |
Correct |
102 ms |
13336 KB |
Output is correct |
28 |
Correct |
137 ms |
16708 KB |
Output is correct |
29 |
Correct |
683 ms |
96512 KB |
Output is correct |
30 |
Correct |
426 ms |
55444 KB |
Output is correct |
31 |
Correct |
408 ms |
55368 KB |
Output is correct |
32 |
Correct |
659 ms |
96512 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 |
6 ms |
7380 KB |
Output is correct |
38 |
Correct |
5 ms |
7380 KB |
Output is correct |
39 |
Correct |
4 ms |
7384 KB |
Output is correct |
40 |
Correct |
4 ms |
7380 KB |
Output is correct |
41 |
Correct |
4 ms |
7380 KB |
Output is correct |
42 |
Correct |
4 ms |
7252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7380 KB |
Output is correct |
2 |
Correct |
66 ms |
9348 KB |
Output is correct |
3 |
Correct |
35 ms |
9292 KB |
Output is correct |
4 |
Correct |
103 ms |
36940 KB |
Output is correct |
5 |
Correct |
73 ms |
37700 KB |
Output is correct |
6 |
Correct |
264 ms |
36844 KB |
Output is correct |
7 |
Correct |
45 ms |
9332 KB |
Output is correct |
8 |
Correct |
161 ms |
36840 KB |
Output is correct |
9 |
Correct |
103 ms |
37588 KB |
Output is correct |
10 |
Correct |
131 ms |
37504 KB |
Output is correct |
11 |
Correct |
159 ms |
22944 KB |
Output is correct |
12 |
Correct |
150 ms |
30508 KB |
Output is correct |
13 |
Correct |
169 ms |
23152 KB |
Output is correct |
14 |
Correct |
303 ms |
36940 KB |
Output is correct |
15 |
Correct |
271 ms |
37040 KB |
Output is correct |
16 |
Correct |
5 ms |
7384 KB |
Output is correct |
17 |
Correct |
6 ms |
7380 KB |
Output is correct |
18 |
Correct |
5 ms |
7380 KB |
Output is correct |
19 |
Correct |
5 ms |
7376 KB |
Output is correct |
20 |
Correct |
5 ms |
7380 KB |
Output is correct |
21 |
Correct |
4 ms |
7380 KB |
Output is correct |
22 |
Correct |
4 ms |
7380 KB |
Output is correct |
23 |
Correct |
5 ms |
7380 KB |
Output is correct |
24 |
Correct |
4 ms |
7380 KB |
Output is correct |
25 |
Correct |
4 ms |
7384 KB |
Output is correct |