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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, m, k; cin >> n >> m >> k;
vector<int> c(n);
for (int i = 0; i < n; ++i) {
cin >> c[i]; --c[i];
}
vector<vector<int>> g(n);
while (m--) {
int u, v; cin >> u >> v; --u, --v;
g[u].push_back(v);
g[v].push_back(u);
}
long long res = 0;
vector dp(n, vector<long long>(1 << k));
for (int i = 0; i < n; ++i) {
dp[i][1 << c[i]] = 1;
}
for (int m = 1; m < 1 << k; ++m) {
for (int i = 0; i < n; ++i) {
if (dp[i][m]) {
for (int j : g[i]) {
if (!(m >> c[j] & 1)) {
dp[j][m + (1 << c[j])] += dp[i][m];
}
}
if (__builtin_popcount(m) > 1) {
res += dp[i][m];
}
}
}
}
cout << res;
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... |