Submission #689965

#TimeUsernameProblemLanguageResultExecution timeMemory
689965NK_Paths (BOI18_paths)C++17
100 / 100
446 ms70728 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 = long long; 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)); for(int i = 0; i < N; i++) dp[i][1<<A[i]] = 1; ll ans = 0; for(int s = 1; s < (1<<K); s++) { for(int u = 0; u < N; u++) if (dp[u][s] != 0) { // cout << "FIN: " << u << " " << s << " " << dp[u][s] << nl; if (__builtin_popcount(s) != 1) ans += dp[u][s]; for(auto v : adj[u]) { if ((s >> A[v]) & 1) continue; dp[v][s^(1<<A[v])] += dp[u][s]; // cout << "MOVE: " << v << " " << (s ^ (1<<A[v])) << " " << dp[v][s^(1<<A[v])] << nl; } } } 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...