This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
using ll = int64_t;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, M, K; cin >> N >> M >> K;
vector<int> A(N); for(auto& x : A) { cin >> x; --x; }
vector<vector<int>> adj(N);
for(int i = 0; i < M; i++) {
int u, v; cin >> u >> v; --u, --v;
// cout << u << " " << v << nl;
adj[u].push_back(v);
adj[v].push_back(u);
}
vector<vector<ll>> dp(N, vector<ll>(1<<K, 0));
for(int i = 0; i < N; i++) dp[i][1<<A[i]] = 1;
ll ans = 0;
int P2 = 1;
for(int s = 1; s < (1<<K); s++) {
for(int u = 0; u < N; u++) if (dp[u][s] != 0) {
if (s == P2) { ans += dp[u][s]; P2 += P2; }
for(const auto &v : adj[u]) if (((s >> A[v]) & 1) ^ 1) dp[v][s^(1<<A[v])] += dp[u][s];
}
}
cout << ans << nl;
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... |