#include "bits/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
<< ": "; \
dbgh(__VA_ARGS__)
#else
#define cerr \
if (false) \
cerr
#define dbg(...)
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
bool on(int x, int i) {
return (x >> i) & 1;
}
void solve() {
int n, m, k;
cin >> n >> m >> k;
int arr[n];
for (auto& a : arr) {
cin >> a;
a--;
}
vector<int> graph[n];
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
u--;
v--;
graph[u].push_back(v);
graph[v].push_back(u);
}
long dp[1 << k][n] {};
for (int i = 0; i < n; i++) {
dp[1 << arr[i]][i] = 1;
}
for (int i = 0; i < (1 << k); i++) {
for (int j = 0; j < n; j++) {
if (on(i, arr[j])) {
for (auto& v : graph[j]) {
dp[i][j] += dp[i ^ (1 << arr[j])][v];
}
}
}
}
long ans = 0;
for (int i = 0; i < (1 << k); i++) {
if (__builtin_popcount(i) >= 2) {
for (int j = 0; j < n; j++) {
ans += dp[i][j];
}
}
}
cout << ans << endl;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cin.exceptions(ios::failbit);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
324 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
7208 KB |
Output is correct |
2 |
Correct |
46 ms |
6140 KB |
Output is correct |
3 |
Correct |
227 ms |
40092 KB |
Output is correct |
4 |
Correct |
80 ms |
9804 KB |
Output is correct |
5 |
Correct |
88 ms |
9292 KB |
Output is correct |
6 |
Correct |
161 ms |
29476 KB |
Output is correct |
7 |
Correct |
230 ms |
40120 KB |
Output is correct |
8 |
Correct |
227 ms |
40860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
324 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
58 ms |
7208 KB |
Output is correct |
12 |
Correct |
46 ms |
6140 KB |
Output is correct |
13 |
Correct |
227 ms |
40092 KB |
Output is correct |
14 |
Correct |
80 ms |
9804 KB |
Output is correct |
15 |
Correct |
88 ms |
9292 KB |
Output is correct |
16 |
Correct |
161 ms |
29476 KB |
Output is correct |
17 |
Correct |
230 ms |
40120 KB |
Output is correct |
18 |
Correct |
227 ms |
40860 KB |
Output is correct |
19 |
Correct |
57 ms |
7144 KB |
Output is correct |
20 |
Correct |
45 ms |
6216 KB |
Output is correct |
21 |
Correct |
216 ms |
40048 KB |
Output is correct |
22 |
Correct |
77 ms |
9784 KB |
Output is correct |
23 |
Correct |
74 ms |
9352 KB |
Output is correct |
24 |
Correct |
151 ms |
29460 KB |
Output is correct |
25 |
Correct |
216 ms |
40140 KB |
Output is correct |
26 |
Correct |
220 ms |
40856 KB |
Output is correct |
27 |
Correct |
46 ms |
6164 KB |
Output is correct |
28 |
Correct |
61 ms |
8664 KB |
Output is correct |
29 |
Correct |
277 ms |
58880 KB |
Output is correct |
30 |
Correct |
165 ms |
32968 KB |
Output is correct |
31 |
Correct |
167 ms |
33084 KB |
Output is correct |
32 |
Correct |
276 ms |
58960 KB |
Output is correct |
33 |
Correct |
1 ms |
316 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
320 KB |
Output is correct |
41 |
Correct |
0 ms |
320 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
17 ms |
2192 KB |
Output is correct |
3 |
Correct |
16 ms |
2208 KB |
Output is correct |
4 |
Correct |
50 ms |
13436 KB |
Output is correct |
5 |
Correct |
39 ms |
14144 KB |
Output is correct |
6 |
Correct |
101 ms |
32160 KB |
Output is correct |
7 |
Correct |
16 ms |
2188 KB |
Output is correct |
8 |
Correct |
68 ms |
19576 KB |
Output is correct |
9 |
Correct |
50 ms |
20416 KB |
Output is correct |
10 |
Correct |
63 ms |
20232 KB |
Output is correct |
11 |
Correct |
54 ms |
17036 KB |
Output is correct |
12 |
Correct |
57 ms |
25120 KB |
Output is correct |
13 |
Correct |
52 ms |
17252 KB |
Output is correct |
14 |
Correct |
95 ms |
32164 KB |
Output is correct |
15 |
Correct |
97 ms |
32236 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
320 KB |
Output is correct |
20 |
Correct |
0 ms |
316 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
316 KB |
Output is correct |