Submission #493169

#TimeUsernameProblemLanguageResultExecution timeMemory
493169MilosMilutinovicPaths (BOI18_paths)C++14
100 / 100
403 ms70768 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, k; cin >> n >> m >> k; vector<int> a(n); vector<vector<long long>> dp(n, vector<long long>(1 << k)); for (int i = 0; i < n; i++) { cin >> a[i]; --a[i]; dp[i][1 << a[i]] = 1; } vector<vector<int>> g(n); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; --u, --v; g[u].push_back(v); g[v].push_back(u); } for (int j = 0; j < (1 << k); j++) { for (int i = 0; i < n; i++) { if ((j & (1 << a[i]))) { continue; } for (int x : g[i]) { if (!(j & (1 << a[x]))) { continue; } dp[i][j ^ (1 << a[i])] += dp[x][j]; } } } long long ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < (1 << k); j++) { ans += dp[i][j]; } } cout << ans - n << '\n'; 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...