This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author: hashman
* created:
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
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);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
--a; --b;
g[a].push_back(b);
g[b].push_back(a);
}
vector<vector<int64_t>> dp(n, vector<int64_t>(1 << k));
for (int i = 0; i < n; i++) {
dp[i][1 << c[i]] = 1;
}
for (int j = 1; j < (1 << k); j++) {
for (int i = 0; i < n; i++) {
if (j & (1 << c[i])) {
for (int prv : g[i]) {
dp[i][j] += dp[prv][j - (1 << c[i])];
}
}
}
}
int64_t ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 1; j < (1 << k); j++) {
ans += dp[i][j];
}
}
cout << ans - n << '\n';
}
# | 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... |