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>
typedef long long ll;
int cnt(int x) {
int r = 0;
while (x) {
r += x & 1;
x >>= 1;
}
return r;
}
int main() {
std::ios::sync_with_stdio(0); std::cin.tie(0);
int n, m, k; std::cin >> n >> m >> k;
std::vector <int> col(n);
std::vector <std::vector <ll>> dp(3e5 + 5, std::vector <ll> (32, 0));
for (int i = 0; i < n; i++) {
std::cin >> col[i]; col[i]--;
dp[i][1 << col[i]] = 1;
}
std::vector <std::vector <int>> g(n);
for (int i = 0; i < m; i++) {
int u, v; std::cin >> u >> v; u--, v--;
g[u].push_back(v);
g[v].push_back(u);
}
for (int i = 1; i < k; i++)
for (int j = 0; j < n; j++)
for (int l = 1; l < 32; l++) {
if (cnt(l) != i) continue;
for (int x : g[j])
if (!(l & (1 << col[x])))
dp[x][(l ^ (1 << col[x]))] += dp[j][l];
}
ll ans = -n;
for (int i = 0; i < n; i++)
for (int j = 1; j < 32; j++)
ans += dp[i][j];
std::cout << ans << "\n";
}
# | 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... |