Submission #689967

#TimeUsernameProblemLanguageResultExecution timeMemory
689967NK_Paths (BOI18_paths)C++17
0 / 100
66 ms4220 KiB
// 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...