Submission #716412

#TimeUsernameProblemLanguageResultExecution timeMemory
716412ajab_01Paths (BOI18_paths)C++17
100 / 100
487 ms96016 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int N = 3e5 + 5; const int K = 5; vector<int> g[N]; int dp[N][(1 << K)] , C[N] , ans , n , m , k; int32_t main(){ ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); 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 u , v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } 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 j : g[i]) dp[i][mask] += dp[j][mask ^ (1 << C[i])]; ans += dp[i][mask]; } } } cout << ans << '\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...