Submission #532648

#TimeUsernameProblemLanguageResultExecution timeMemory
532648fatemetmhrPaths (BOI18_paths)C++17
100 / 100
306 ms61296 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back const int maxn5 = 3e5 + 10; vector <int> adj[maxn5]; int a[maxn5]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; ll dp[(1<<k) + 1][n + 2]; memset(dp, 0, sizeof dp); for(int i = 0; i < n; i++){ cin >> a[i]; a[i]--; dp[1<<a[i]][i] = 1; } for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; a--; b--; adj[a].pb(b); adj[b].pb(a); } ll ans = 0; for(int mask = 1; mask < (1 << k); mask++) if(__builtin_popcount(mask) > 1) for(int i = 0; i < n; i++) if((mask >> a[i])&1){ for(auto u : adj[i]) dp[mask][i] += dp[mask ^ (1 << a[i])][u]; ans += dp[mask][i]; } 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...