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 n, m, k;
int c[300010];
int f[300010][1 << 5];
vector <int> adj[300010];
long long res;
int main() {
ios_base :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> m >> k;
for (int i = 1; i <= n; ++i) {
cin >> c[i];
--c[i];
}
for (int i = 1; i <= m; ++i) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int mask = 1; mask < (1 << k); ++mask) {
if (__builtin_popcount(mask) == 1) {
int cl = __builtin_ctz(mask);
for (int u = 1; u <= n; ++u)
if (cl == c[u]) f[u][mask] = 1;
} else {
for (int u = 1; u <= n; ++u) {
if (!((mask >> c[u]) & 1)) continue;
for (auto v: adj[u]) {
if (c[u] == c[v]) continue;
f[u][mask] += f[v][mask ^ (1 << c[u])];
}
}
}
}
for (int mask = 1; mask < (1 << k); ++mask) {
if (__builtin_popcount(mask) == 1) continue;
for (int u = 1; u <= n; ++u) res += f[u][mask];
}
cout << res;
}
# | 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... |