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 ll = long long;
template <class T>
using Vec = std::vector<T>;
int main() {
int N, M, K;
std::cin >> N >> M >> K;
Vec<int> col(N);
for (auto& x: col) {
std::cin >> x;
x -= 1;
}
Vec<Vec<int>> graph(N);
for (int i = 0; i < M; ++i) {
int a, b;
std::cin >> a >> b;
a -= 1;
b -= 1;
graph[a].push_back(b);
graph[b].push_back(a);
}
Vec<Vec<ll>> count(N, Vec<ll>(1 << K));
for (int i = 0; i < N; ++i) {
count[i][1 << col[i]] += 1;
}
for (int set = 0; set < (1 << K); ++set) {
for (int i = 0; i < N; ++i) {
if (!(set >> col[i] & 1)) {
continue;
}
for (const auto j: graph[i]) {
count[i][set] += count[j][set & ~(1 << col[i])];
}
}
}
ll ans = 0;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < (1 << K); ++j) {
if (__builtin_popcount(j) >= 2) {
ans += count[i][j];
}
}
}
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... |