#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m, K;
cin >> n >> m >> K;
vector<int> cols;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
x--;
cols.push_back(x);
}
vector<vector<int>> graph(n);
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
a--; b--;
graph[a].push_back(b);
graph[b].push_back(a);
}
vector<vector<long long>> dp(n+1, vector<long long> ((1 << K) +1));
for (int i = 0; i < n; i++)
{
dp[i][1 << cols[i]] = 1;
}
for (int k = 1; k < (1 << K); k++)
{
for (int i = 0; i < n; i++)
{
if (!(k & (1 << cols[i])))
{
continue;
}
for (int v: graph[i])
{
if (!(k & (1 << cols[v])))
{
dp[v][k ^ (1 << cols[v])] += dp[i][k];
}
}
}
}
long long res = 0;
for(auto i: dp)
{
for (auto j: i)
{
res += j;
}
}
cout << res - n<< "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
512 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
264 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
125 ms |
4404 KB |
Output is correct |
2 |
Correct |
76 ms |
3908 KB |
Output is correct |
3 |
Correct |
754 ms |
47596 KB |
Output is correct |
4 |
Correct |
189 ms |
7288 KB |
Output is correct |
5 |
Correct |
186 ms |
6780 KB |
Output is correct |
6 |
Correct |
462 ms |
33444 KB |
Output is correct |
7 |
Correct |
774 ms |
47748 KB |
Output is correct |
8 |
Correct |
753 ms |
48080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
512 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
264 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
125 ms |
4404 KB |
Output is correct |
12 |
Correct |
76 ms |
3908 KB |
Output is correct |
13 |
Correct |
754 ms |
47596 KB |
Output is correct |
14 |
Correct |
189 ms |
7288 KB |
Output is correct |
15 |
Correct |
186 ms |
6780 KB |
Output is correct |
16 |
Correct |
462 ms |
33444 KB |
Output is correct |
17 |
Correct |
774 ms |
47748 KB |
Output is correct |
18 |
Correct |
753 ms |
48080 KB |
Output is correct |
19 |
Correct |
113 ms |
4344 KB |
Output is correct |
20 |
Correct |
90 ms |
4088 KB |
Output is correct |
21 |
Correct |
768 ms |
47516 KB |
Output is correct |
22 |
Correct |
189 ms |
7304 KB |
Output is correct |
23 |
Correct |
168 ms |
6796 KB |
Output is correct |
24 |
Correct |
451 ms |
33260 KB |
Output is correct |
25 |
Correct |
795 ms |
47496 KB |
Output is correct |
26 |
Correct |
821 ms |
48176 KB |
Output is correct |
27 |
Correct |
115 ms |
4008 KB |
Output is correct |
28 |
Correct |
182 ms |
5888 KB |
Output is correct |
29 |
Correct |
1406 ms |
66184 KB |
Output is correct |
30 |
Correct |
737 ms |
34944 KB |
Output is correct |
31 |
Correct |
807 ms |
35088 KB |
Output is correct |
32 |
Correct |
1273 ms |
66308 KB |
Output is correct |
33 |
Correct |
2 ms |
384 KB |
Output is correct |
34 |
Correct |
2 ms |
428 KB |
Output is correct |
35 |
Correct |
2 ms |
384 KB |
Output is correct |
36 |
Correct |
2 ms |
384 KB |
Output is correct |
37 |
Correct |
2 ms |
384 KB |
Output is correct |
38 |
Correct |
3 ms |
384 KB |
Output is correct |
39 |
Correct |
3 ms |
384 KB |
Output is correct |
40 |
Correct |
2 ms |
384 KB |
Output is correct |
41 |
Correct |
2 ms |
384 KB |
Output is correct |
42 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
37 ms |
1408 KB |
Output is correct |
3 |
Correct |
33 ms |
1448 KB |
Output is correct |
4 |
Correct |
191 ms |
16032 KB |
Output is correct |
5 |
Correct |
141 ms |
16836 KB |
Output is correct |
6 |
Correct |
412 ms |
34640 KB |
Output is correct |
7 |
Correct |
30 ms |
1408 KB |
Output is correct |
8 |
Correct |
296 ms |
22360 KB |
Output is correct |
9 |
Correct |
201 ms |
23028 KB |
Output is correct |
10 |
Correct |
253 ms |
22992 KB |
Output is correct |
11 |
Correct |
184 ms |
18076 KB |
Output is correct |
12 |
Correct |
256 ms |
26812 KB |
Output is correct |
13 |
Correct |
206 ms |
18128 KB |
Output is correct |
14 |
Correct |
531 ms |
34884 KB |
Output is correct |
15 |
Correct |
525 ms |
34976 KB |
Output is correct |
16 |
Correct |
2 ms |
300 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
256 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |