#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll infll = 1e18;
template<typename T>
istream &operator>>(istream &is, vector<T> &a) {
for (auto &i : a) {
is >> i;
}
return is;
}
int bit(int mask, int i) {
return (mask >> i) & 1;
}
int32_t main() {
#ifdef LOCAL
freopen("/tmp/input.txt", "r", stdin);
#else
ios::sync_with_stdio(false);
cin.tie(nullptr);
#endif
int n, m, k;
cin >> n >> m >> k;
vector<int> c(n);
cin >> c;
for (auto &i : c) {
--i;
}
vector<vector<int>> g(n);
for (int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
--u, --v;
g[u].push_back(v);
g[v].push_back(u);
}
vector<vector<ll>> dp(1 << k, vector<ll>(n));
for (int i = 0; i < n; ++i) {
dp[1 << c[i]][i] = 1;
}
for (int mask = 0; mask < (1 << k); ++mask) {
for (int i = 0; i < n; ++i) {
if (!bit(mask, c[i])) {
continue;
}
for (auto j : g[i]) {
if (!bit(mask, c[j])) {
dp[mask ^ (1 << c[j])][j] += dp[mask][i];
}
}
}
}
ll sum = 0;
for (int mask = 0; mask < (1 << k); ++mask) {
for (int i = 0; i < n; ++i) {
sum += dp[mask][i];
}
}
cout << sum - n << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
7252 KB |
Output is correct |
2 |
Correct |
38 ms |
6236 KB |
Output is correct |
3 |
Correct |
153 ms |
42516 KB |
Output is correct |
4 |
Correct |
62 ms |
10072 KB |
Output is correct |
5 |
Correct |
58 ms |
9708 KB |
Output is correct |
6 |
Correct |
111 ms |
31172 KB |
Output is correct |
7 |
Correct |
155 ms |
42440 KB |
Output is correct |
8 |
Correct |
161 ms |
43124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
47 ms |
7252 KB |
Output is correct |
12 |
Correct |
38 ms |
6236 KB |
Output is correct |
13 |
Correct |
153 ms |
42516 KB |
Output is correct |
14 |
Correct |
62 ms |
10072 KB |
Output is correct |
15 |
Correct |
58 ms |
9708 KB |
Output is correct |
16 |
Correct |
111 ms |
31172 KB |
Output is correct |
17 |
Correct |
155 ms |
42440 KB |
Output is correct |
18 |
Correct |
161 ms |
43124 KB |
Output is correct |
19 |
Correct |
48 ms |
7256 KB |
Output is correct |
20 |
Correct |
38 ms |
6236 KB |
Output is correct |
21 |
Correct |
146 ms |
42580 KB |
Output is correct |
22 |
Correct |
60 ms |
10148 KB |
Output is correct |
23 |
Correct |
60 ms |
9552 KB |
Output is correct |
24 |
Correct |
110 ms |
31172 KB |
Output is correct |
25 |
Correct |
148 ms |
42640 KB |
Output is correct |
26 |
Correct |
145 ms |
43092 KB |
Output is correct |
27 |
Correct |
50 ms |
6224 KB |
Output is correct |
28 |
Correct |
61 ms |
8788 KB |
Output is correct |
29 |
Correct |
219 ms |
61268 KB |
Output is correct |
30 |
Correct |
132 ms |
34248 KB |
Output is correct |
31 |
Correct |
168 ms |
34276 KB |
Output is correct |
32 |
Correct |
202 ms |
61244 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
344 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 |
456 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
28 ms |
2396 KB |
Output is correct |
3 |
Correct |
14 ms |
2140 KB |
Output is correct |
4 |
Correct |
45 ms |
14164 KB |
Output is correct |
5 |
Correct |
33 ms |
15064 KB |
Output is correct |
6 |
Correct |
92 ms |
33116 KB |
Output is correct |
7 |
Correct |
17 ms |
2156 KB |
Output is correct |
8 |
Correct |
57 ms |
20564 KB |
Output is correct |
9 |
Correct |
62 ms |
21420 KB |
Output is correct |
10 |
Correct |
42 ms |
21192 KB |
Output is correct |
11 |
Correct |
51 ms |
17612 KB |
Output is correct |
12 |
Correct |
55 ms |
25836 KB |
Output is correct |
13 |
Correct |
55 ms |
17740 KB |
Output is correct |
14 |
Correct |
92 ms |
33116 KB |
Output is correct |
15 |
Correct |
98 ms |
33104 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |