Submission #716554

#TimeUsernameProblemLanguageResultExecution timeMemory
716554AranMasterPaths (BOI18_paths)C++17
53 / 100
167 ms31256 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; vector <int> adj[maxn]; int dp[maxn][32]; int c[maxn]; int n, m , k; int main(){ cin >> n >> m >> k; for(int i = 1; i <= n; i++){ cin >> c[i]; c[i]--; dp[i][1 << c[i]] = 1; } for(int i = 1; i <= m; i++){ int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } long long ans = 0; for(int mask = 1; mask < (1 << k); mask++){ if(__builtin_popcount(mask) == 1) continue; for(int i = 1; i <= n; i++){ if(mask & (1 << c[i])){ for(int u : adj[i]){ dp[i][mask] += dp[u][mask ^ (1 << c[i])]; } ans += dp[i][mask]; } } } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...