#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 998244353;
const ll LOGN = 18;
const ll INF = 1e15;
const ll MAXN = 3e5 + 5;
vector<vector<int>> graph;
int t[MAXN], dp[MAXN][32];
int main() {
fast
int N, M, K, a, b;
cin >> N >> M >> K;
graph = vector<vector<int>>(N+1, vector<int>());
for (int i = 1; i <= N; i++) {
cin >> t[i], t[i]--;
for (int msk = 0; msk < 32; msk++)
dp[i][msk] = 0;
dp[i][1<<t[i]] = 1;
}
for (int i = 0; i < M; i++) {
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
}
for (int cnt = 2; cnt <= K; cnt++) {
for (int msk = 0; msk < 32; msk++) {
if (__builtin_popcount(msk) != cnt)
continue;
for (int node = 1; node <= N; node++) {
int m = 1<<t[node];
if ((m & msk) == 0)
continue;
for (auto u : graph[node])
dp[node][msk] += dp[u][msk ^ m];
}
}
}
ll ans = 0;
for (int i = 1; i <= N; i++) {
for (int msk = 0; msk < 32; msk++)
ans += dp[i][msk];
}
cout << ans - N << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 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 |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
6404 KB |
Output is correct |
2 |
Correct |
38 ms |
3932 KB |
Output is correct |
3 |
Correct |
319 ms |
59048 KB |
Output is correct |
4 |
Correct |
61 ms |
13136 KB |
Output is correct |
5 |
Correct |
57 ms |
13144 KB |
Output is correct |
6 |
Correct |
219 ms |
43972 KB |
Output is correct |
7 |
Correct |
287 ms |
59040 KB |
Output is correct |
8 |
Correct |
302 ms |
59708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 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 |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
49 ms |
6404 KB |
Output is correct |
12 |
Correct |
38 ms |
3932 KB |
Output is correct |
13 |
Correct |
319 ms |
59048 KB |
Output is correct |
14 |
Correct |
61 ms |
13136 KB |
Output is correct |
15 |
Correct |
57 ms |
13144 KB |
Output is correct |
16 |
Correct |
219 ms |
43972 KB |
Output is correct |
17 |
Correct |
287 ms |
59040 KB |
Output is correct |
18 |
Correct |
302 ms |
59708 KB |
Output is correct |
19 |
Correct |
48 ms |
9296 KB |
Output is correct |
20 |
Correct |
39 ms |
6360 KB |
Output is correct |
21 |
Correct |
323 ms |
58964 KB |
Output is correct |
22 |
Correct |
66 ms |
13252 KB |
Output is correct |
23 |
Correct |
57 ms |
13136 KB |
Output is correct |
24 |
Correct |
197 ms |
43812 KB |
Output is correct |
25 |
Correct |
295 ms |
58836 KB |
Output is correct |
26 |
Correct |
314 ms |
59652 KB |
Output is correct |
27 |
Correct |
50 ms |
6224 KB |
Output is correct |
28 |
Correct |
54 ms |
10068 KB |
Output is correct |
29 |
Correct |
351 ms |
58964 KB |
Output is correct |
30 |
Correct |
250 ms |
35012 KB |
Output is correct |
31 |
Correct |
215 ms |
34908 KB |
Output is correct |
32 |
Correct |
382 ms |
58964 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
464 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
13 ms |
1628 KB |
Output is correct |
3 |
Correct |
12 ms |
2136 KB |
Output is correct |
4 |
Correct |
73 ms |
21852 KB |
Output is correct |
5 |
Correct |
58 ms |
22616 KB |
Output is correct |
6 |
Correct |
83 ms |
21844 KB |
Output is correct |
7 |
Correct |
13 ms |
2140 KB |
Output is correct |
8 |
Correct |
76 ms |
21844 KB |
Output is correct |
9 |
Correct |
76 ms |
22612 KB |
Output is correct |
10 |
Correct |
76 ms |
22476 KB |
Output is correct |
11 |
Correct |
35 ms |
10968 KB |
Output is correct |
12 |
Correct |
43 ms |
17044 KB |
Output is correct |
13 |
Correct |
37 ms |
11356 KB |
Output is correct |
14 |
Correct |
101 ms |
21852 KB |
Output is correct |
15 |
Correct |
82 ms |
21840 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |