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(0);
cin.tie(0);
int N, M, K;
cin >> N >> M >> K;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
A[i]--;
}
vector<vector<int>> adj(N);
while (M--) {
int u, v;
cin >> u >> v;
u--, v--;
adj[u].emplace_back(v);
adj[v].emplace_back(u);
}
vector<vector<long long>> dp(N, vector<long long>(1 << K));
for (int mask = (1 << K) - 1; mask >= 0; mask--) {
for (int i = 0; i < N; i++) if ((mask >> A[i]) & 1) {
dp[i][mask] += 1;
}
for (int i = 0; i < N; i++) if ((mask >> A[i]) & 1) {
for (auto j : adj[i]) if (((mask >> A[j]) & 1) ^ 1) {
dp[i][mask] += dp[j][mask | (1 << A[j])];
}
}
}
long long ans = 0;
for (int i = 0; i < N; i++) {
ans += dp[i][1 << A[i]];
}
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... |