#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300000;
int n,m,k;
vector<vector<int>> g;
int c[MAXN];
long long res = 0;
long long dp[MAXN][32];
void edit(int node, int num) {
for (int i=0;i<(1<<k);i++) {
if (((1<<c[node])&i) == 0) continue;
if (__builtin_popcount(i) != num) continue;
for (int x:g[node]) {
dp[node][i] += dp[x][(i ^ (1<<c[node]))];
}
}
}
void all(int num) {
for (int i=0;i<n;i++) {
edit(i, num);
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m>>k;
for (int i=0;i<n;i++) {
cin>>c[i];c[i]--;
}
g.resize(n);
for (int i=0;i<m;i++) {
int a,b;cin>>a>>b;a--;b--;
g[a].push_back(b);
g[b].push_back(a);
}
for (int i=0;i<n;i++) {
dp[i][(1<<c[i])] = 1;
}
for (int i=2;i<=k;i++) {
all(i);
}
for (int i=0;i<n;i++) {
for (int j=0;j<32;j++) {
res += dp[i][j];
}
}
res -= n;
cout<<res<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2512 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
11088 KB |
Output is correct |
2 |
Correct |
34 ms |
10580 KB |
Output is correct |
3 |
Correct |
250 ms |
96596 KB |
Output is correct |
4 |
Correct |
63 ms |
19344 KB |
Output is correct |
5 |
Correct |
74 ms |
19212 KB |
Output is correct |
6 |
Correct |
161 ms |
69652 KB |
Output is correct |
7 |
Correct |
270 ms |
96632 KB |
Output is correct |
8 |
Correct |
302 ms |
97192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2512 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2508 KB |
Output is correct |
11 |
Correct |
44 ms |
11088 KB |
Output is correct |
12 |
Correct |
34 ms |
10580 KB |
Output is correct |
13 |
Correct |
250 ms |
96596 KB |
Output is correct |
14 |
Correct |
63 ms |
19344 KB |
Output is correct |
15 |
Correct |
74 ms |
19212 KB |
Output is correct |
16 |
Correct |
161 ms |
69652 KB |
Output is correct |
17 |
Correct |
270 ms |
96632 KB |
Output is correct |
18 |
Correct |
302 ms |
97192 KB |
Output is correct |
19 |
Correct |
44 ms |
11096 KB |
Output is correct |
20 |
Correct |
36 ms |
10384 KB |
Output is correct |
21 |
Correct |
252 ms |
96548 KB |
Output is correct |
22 |
Correct |
59 ms |
19336 KB |
Output is correct |
23 |
Correct |
57 ms |
19276 KB |
Output is correct |
24 |
Correct |
154 ms |
69620 KB |
Output is correct |
25 |
Correct |
248 ms |
96596 KB |
Output is correct |
26 |
Correct |
319 ms |
97496 KB |
Output is correct |
27 |
Correct |
37 ms |
10588 KB |
Output is correct |
28 |
Correct |
50 ms |
12116 KB |
Output is correct |
29 |
Correct |
373 ms |
96424 KB |
Output is correct |
30 |
Correct |
211 ms |
54980 KB |
Output is correct |
31 |
Correct |
203 ms |
54980 KB |
Output is correct |
32 |
Correct |
382 ms |
96556 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
14 ms |
4316 KB |
Output is correct |
3 |
Correct |
12 ms |
4444 KB |
Output is correct |
4 |
Correct |
67 ms |
35840 KB |
Output is correct |
5 |
Correct |
46 ms |
36560 KB |
Output is correct |
6 |
Correct |
133 ms |
35688 KB |
Output is correct |
7 |
Correct |
14 ms |
4440 KB |
Output is correct |
8 |
Correct |
93 ms |
35696 KB |
Output is correct |
9 |
Correct |
65 ms |
36552 KB |
Output is correct |
10 |
Correct |
85 ms |
36284 KB |
Output is correct |
11 |
Correct |
54 ms |
20940 KB |
Output is correct |
12 |
Correct |
75 ms |
28880 KB |
Output is correct |
13 |
Correct |
58 ms |
21068 KB |
Output is correct |
14 |
Correct |
128 ms |
35728 KB |
Output is correct |
15 |
Correct |
136 ms |
35884 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2408 KB |
Output is correct |
18 |
Correct |
1 ms |
2516 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |