Submission #864452

#TimeUsernameProblemLanguageResultExecution timeMemory
864452maks007Paths (BOI18_paths)C++14
100 / 100
523 ms73820 KiB
#include "bits/stdc++.h" using namespace std; #define int long long vector <int> color; vector <vector <int>> g, dp; signed main () { int n, m, k; cin >> n >> m >> k; color.resize(n); g.resize(n); dp.resize(n, vector <int> (1 << k, 0)); for(int i = 0; i < n; i ++) { cin >> color[i]; color[i] --; } for(int i = 0, u, v; i < m; i ++) { cin >> u >> v; u --, v --; g[u].push_back(v); g[v].push_back(u); if(color[u] == color[v]) continue; dp[v][(1 << color[u]) ^ (1 << color[v])] += 1; dp[u][(1 << color[u]) ^ (1 << color[v])] += 1; } for(int mask = 0; mask < (1 << k); mask ++) { for(int i = 0; i < n; i ++) { if(dp[i][mask] == 0 || (!(mask & (1 << color[i])))) continue; for(auto j : g[i]) { if(mask & (1 << color[j])) continue; dp[j][mask ^ (1 << color[j])] += dp[i][mask]; } } } int ans = 0; for(int mask = 0; mask < (1 << k); mask ++) { for(int i = 0; i < n; i ++) { ans += dp[i][mask]; } } cout << ans; 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...