Submission #689968

#TimeUsernameProblemLanguageResultExecution timeMemory
689968NK_Paths (BOI18_paths)C++17
100 / 100
444 ms66216 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, 0)); for(int i = 0; i < N; i++) dp[i][1<<A[i]] = 1; int P2 = 1; ll ans = 0; for(int s = 1; s < (1<<K); s++) { if (P2 < s) P2 += P2; for(int u = 0; u < N; u++) if (dp[u][s] != 0) { if (s != P2) ans += dp[u][s]; 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...