Submission #941007

#TimeUsernameProblemLanguageResultExecution timeMemory
941007phoenix0423Paths (BOI18_paths)C++17
100 / 100
468 ms100692 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pll; #define fastio ios::sync_with_stdio(false), cin.tie(0) #define pb push_back #define eb emplace_back #define f first #define s second #define int long long #define lowbit(x) x&-x const int maxn = 3e5 + 5; vector<int> adj[maxn]; int c[maxn]; int n, m, k; int dp[maxn][32]; signed main(void){ fastio; cin>>n>>m>>k; for(int i = 0; i < n; i++) cin>>c[i], c[i]--; for(int i = 0; i < m; i++){ int a, b; cin>>a>>b; a--, b--; adj[a].pb(b); adj[b].pb(a); } for(int i = 0; i < n; i++) dp[i][(1 << c[i])] = 1; int ans = 0; for(int rd = 1; rd < k; rd++){ for(int i = 0; i < n; i++){ for(int mask = 0; mask < (1 << k); mask++){ if(__builtin_popcount(mask) != rd) continue; if(!dp[i][mask]) continue; for(auto x : adj[i]){ if(mask & (1 << c[x])) continue; dp[x][mask | (1 << c[x])] += dp[i][mask]; } } } } for(int i = 0; i < n; i++){ for(int mask = 1; mask < (1 << k); mask++){ if(__builtin_popcount(mask) == 1) continue; ans += dp[i][mask]; } } cout<<ans<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...