#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;
const int MAX_N = 3e5 + 10;
const int MAX_K = 5;
int a[MAX_N], b[MAX_N], c[MAX_N];
long long dp[MAX_N][1<<MAX_K];
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, M, K;
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++) {
cin >> a[i] >> b[i];
}
long long ans = 0;
for(int mask = 1; mask < (1<<K); mask++) {
if(__builtin_popcount(mask) == 1) {
continue;
}
for(int i = 1; i <= M; i++) {
if(mask & (1<<c[a[i]])) {
dp[a[i]][mask] += dp[b[i]][mask ^ (1<<c[a[i]])];
}
if(mask & (1<<c[b[i]])) {
dp[b[i]][mask] += dp[a[i]][mask ^ (1<<c[b[i]])];
}
}
for(int i = 1; i <= N; i++) {
ans += dp[i][mask];
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
6640 KB |
Output is correct |
2 |
Correct |
51 ms |
5036 KB |
Output is correct |
3 |
Correct |
134 ms |
83396 KB |
Output is correct |
4 |
Correct |
56 ms |
13596 KB |
Output is correct |
5 |
Correct |
68 ms |
13648 KB |
Output is correct |
6 |
Correct |
127 ms |
57548 KB |
Output is correct |
7 |
Correct |
141 ms |
83460 KB |
Output is correct |
8 |
Correct |
142 ms |
83504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
57 ms |
6640 KB |
Output is correct |
12 |
Correct |
51 ms |
5036 KB |
Output is correct |
13 |
Correct |
134 ms |
83396 KB |
Output is correct |
14 |
Correct |
56 ms |
13596 KB |
Output is correct |
15 |
Correct |
68 ms |
13648 KB |
Output is correct |
16 |
Correct |
127 ms |
57548 KB |
Output is correct |
17 |
Correct |
141 ms |
83460 KB |
Output is correct |
18 |
Correct |
142 ms |
83504 KB |
Output is correct |
19 |
Correct |
58 ms |
6752 KB |
Output is correct |
20 |
Correct |
50 ms |
5064 KB |
Output is correct |
21 |
Correct |
136 ms |
83448 KB |
Output is correct |
22 |
Correct |
58 ms |
13600 KB |
Output is correct |
23 |
Correct |
69 ms |
13660 KB |
Output is correct |
24 |
Correct |
109 ms |
57680 KB |
Output is correct |
25 |
Correct |
133 ms |
83344 KB |
Output is correct |
26 |
Correct |
142 ms |
83560 KB |
Output is correct |
27 |
Correct |
72 ms |
5016 KB |
Output is correct |
28 |
Correct |
80 ms |
7500 KB |
Output is correct |
29 |
Correct |
196 ms |
83512 KB |
Output is correct |
30 |
Correct |
166 ms |
44980 KB |
Output is correct |
31 |
Correct |
173 ms |
44768 KB |
Output is correct |
32 |
Correct |
200 ms |
83448 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
0 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
42 ms |
1976 KB |
Output is correct |
3 |
Correct |
17 ms |
1872 KB |
Output is correct |
4 |
Correct |
49 ms |
27884 KB |
Output is correct |
5 |
Correct |
42 ms |
27832 KB |
Output is correct |
6 |
Correct |
114 ms |
27792 KB |
Output is correct |
7 |
Correct |
26 ms |
1880 KB |
Output is correct |
8 |
Correct |
71 ms |
27908 KB |
Output is correct |
9 |
Correct |
59 ms |
27852 KB |
Output is correct |
10 |
Correct |
61 ms |
27916 KB |
Output is correct |
11 |
Correct |
74 ms |
14796 KB |
Output is correct |
12 |
Correct |
100 ms |
21504 KB |
Output is correct |
13 |
Correct |
82 ms |
14900 KB |
Output is correct |
14 |
Correct |
100 ms |
27852 KB |
Output is correct |
15 |
Correct |
100 ms |
27908 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
328 KB |
Output is correct |