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 i64 = long long;
constexpr int N = 3e5 + 5;
int n, m, k;
int dp[6][N][32], a[N];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
std::cin >> a[i];
a[i]--;
dp[0][i][1 << a[i]] = 1;
}
std::vector<std::pair<int, int>> e(m);
for (auto &[u, v] : e) {
std::cin >> u >> v;
u--;
v--;
}
for (int K = 1; K < 6; K++) {
for (int msk = 1; msk < 32; msk++) {
for (auto [u, v] : e) {
if (!(msk & (1 << a[u])) || !(msk & (1 << a[v]))) continue;
dp[K][u][msk] += dp[K - 1][v][msk ^ (1 << a[u])];
dp[K][v][msk] += dp[K - 1][u][msk ^ (1 << a[v])];
}
}
}
i64 ans = 0;
for (int K = 1; K < 6; K++) {
for (int msk = 1; msk < 32; msk++) {
for (int i = 0; i < n; i++) {
ans += dp[K][i][msk];
}
}
}
std::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... |