#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lld double
#define int ll
#define usaco(fname) freopen(#fname ".in","r",stdin);freopen(#fname ".out","w",stdout);
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
// const ll INF = 1e18;
const int INF = 1e9;
const int mod = 1e9+7;
const lld PI = acos(-1.0);
int di[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dj[] = {0, 0, 1, -1, 1, -1, 1, -1};
#define debug(x) cout << #x << ": " << x << endl;
#define add(a, b) a += b, a %= mod
#define mul(a, b) ((a % mod) * (b % mod)) % mod
#define all(x) x.begin(),x.end()
void solve() {
int n,m,k;cin>>n>>m>>k;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i], a[i]--;
vector<vector<int>> adj(n, vector<int>());
// bitmask of size k
vector<vector<vector<int>>> dp(n, vector<vector<int>>(k, vector<int>(1 << k)));
// cout << (1 << k) << endl;;
for (int i = 0; i < m; i++) {
int u,v;cin>>u>>v;u--;v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i = 0; i < n; i++) dp[i][0][1 << a[i]]++;
int ans = 0;
for (int j = 1; j < k; j++) {
for (int i = 0; i < n; i++) {
for (auto children : adj[i]) {
for (int mask = 0; mask < (1 << k); mask++) {
if (mask & (1 << a[i])) continue;
dp[i][j][mask | (1 << a[i])] += dp[children][j-1][mask];
}
}
}
}
for (int j = 1; j < k; j++) {
for (int i = 0; i < n; i++) {
for (int mask = 0; mask < (1 << k); mask++) {
ans += dp[i][j][mask];
}
}
}
cout << ans << endl;
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);
int t=1;
while(t--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
444 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 |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
12196 KB |
Output is correct |
2 |
Correct |
48 ms |
9888 KB |
Output is correct |
3 |
Correct |
458 ms |
125824 KB |
Output is correct |
4 |
Correct |
75 ms |
18096 KB |
Output is correct |
5 |
Correct |
59 ms |
15440 KB |
Output is correct |
6 |
Correct |
291 ms |
87232 KB |
Output is correct |
7 |
Correct |
407 ms |
125780 KB |
Output is correct |
8 |
Correct |
425 ms |
126376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
444 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 |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
74 ms |
12196 KB |
Output is correct |
12 |
Correct |
48 ms |
9888 KB |
Output is correct |
13 |
Correct |
458 ms |
125824 KB |
Output is correct |
14 |
Correct |
75 ms |
18096 KB |
Output is correct |
15 |
Correct |
59 ms |
15440 KB |
Output is correct |
16 |
Correct |
291 ms |
87232 KB |
Output is correct |
17 |
Correct |
407 ms |
125780 KB |
Output is correct |
18 |
Correct |
425 ms |
126376 KB |
Output is correct |
19 |
Correct |
63 ms |
12112 KB |
Output is correct |
20 |
Correct |
44 ms |
10076 KB |
Output is correct |
21 |
Correct |
386 ms |
125780 KB |
Output is correct |
22 |
Correct |
72 ms |
18276 KB |
Output is correct |
23 |
Correct |
60 ms |
15444 KB |
Output is correct |
24 |
Correct |
268 ms |
86976 KB |
Output is correct |
25 |
Correct |
377 ms |
125820 KB |
Output is correct |
26 |
Correct |
381 ms |
126288 KB |
Output is correct |
27 |
Correct |
71 ms |
10320 KB |
Output is correct |
28 |
Correct |
111 ms |
17568 KB |
Output is correct |
29 |
Correct |
682 ms |
234084 KB |
Output is correct |
30 |
Correct |
424 ms |
122308 KB |
Output is correct |
31 |
Correct |
452 ms |
122488 KB |
Output is correct |
32 |
Correct |
683 ms |
233852 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
460 KB |
Output is correct |
42 |
Correct |
0 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
45 ms |
4088 KB |
Output is correct |
3 |
Correct |
16 ms |
3420 KB |
Output is correct |
4 |
Correct |
93 ms |
42068 KB |
Output is correct |
5 |
Correct |
89 ms |
42520 KB |
Output is correct |
6 |
Correct |
409 ms |
156500 KB |
Output is correct |
7 |
Correct |
22 ms |
3676 KB |
Output is correct |
8 |
Correct |
186 ms |
78012 KB |
Output is correct |
9 |
Correct |
171 ms |
78532 KB |
Output is correct |
10 |
Correct |
186 ms |
78536 KB |
Output is correct |
11 |
Correct |
227 ms |
79564 KB |
Output is correct |
12 |
Correct |
309 ms |
118088 KB |
Output is correct |
13 |
Correct |
238 ms |
80112 KB |
Output is correct |
14 |
Correct |
452 ms |
156240 KB |
Output is correct |
15 |
Correct |
453 ms |
156476 KB |
Output is correct |
16 |
Correct |
1 ms |
448 KB |
Output is correct |
17 |
Correct |
0 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 |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
600 KB |
Output is correct |