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 main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n);
vector<vector<long long>> dp(n, vector<long long>(1 << k));
for (int i = 0; i < n; i++) {
cin >> a[i];
--a[i];
dp[i][1 << a[i]] = 1;
}
vector<vector<int>> g(n);
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
--u, --v;
g[u].push_back(v);
g[v].push_back(u);
}
for (int j = 0; j < (1 << k); j++) {
for (int i = 0; i < n; i++) {
if ((j & (1 << a[i]))) {
continue;
}
for (int x : g[i]) {
if (!(j & (1 << a[x]))) {
continue;
}
dp[i][j ^ (1 << a[i])] += dp[x][j];
}
}
}
long long ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < (1 << k); j++) {
ans += dp[i][j];
}
}
cout << ans - n << '\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... |