이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |