This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i]--;
}
vector< vector<int> > g(n + 1);
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
vector< vector< vector<long long> > > dp(k, vector< vector<long long> >(n + 1, vector<long long>(1 << k, 0)));
for (int i = 1; i <= n; i++) {
dp[0][i][1 << a[i]] = 1;
}
for (int i = 0; i < k - 1; i++) {
for (int u = 1; u <= n; u++) {
for (int mask = 0; mask < (1 << k); mask++) {
if (dp[i][u][mask] == 0) {
continue;
}
for (auto& v : g[u]) {
if (mask & (1 << a[v])) {
continue;
}
dp[i + 1][v][mask | (1 << a[v])] += dp[i][u][mask];
}
}
}
}
long long ans = 0;
for (int i = 1; i < k; i++) {
for (int u = 1; u <= n; u++) {
for (int mask = 0; mask < (1 << k); mask++) {
ans += dp[i][u][mask];
}
}
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |