Submission #96077

#TimeUsernameProblemLanguageResultExecution timeMemory
96077SecretAgent007Paths (BOI18_paths)C++17
100 / 100
683 ms100424 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define INF 9223372036854775807 int memo[1<<5][300009]; int n, m, k; vector<int> Graph[300009]; vector<int> v; int dp(int mask, int node){ if(memo[mask][node] != -1) return memo[mask][node]; int ans = 0; bool verif = false; for(int i = 4; i >= 0; i--){ if(1<<i & mask){ if(verif) ans = 1; else verif = true; } } for(int a : Graph[node]){ if(!(mask & (1<<v[a]))){ ans+=dp(mask | (1<<v[a]), a); } } //cout << mask << ' ' << node << ' ' << ans << endl; return memo[mask][node] = ans; } signed main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> k; for(int i = 0; i < (1<<5); i++){ for(int j = 0; j < 300009; j++){ memo[i][j] = -1; } } v.resize(n); for(int i = 0; i < n; i++){ cin >> v[i]; v[i]--; } for(int i = 0; i < m; i++){ int a, b; cin >>a >> b; a--; b--; Graph[a].push_back(b); Graph[b].push_back(a); } int ans = 0; for(int i = 0; i < n; i++){ ans+=dp(1<<v[i], 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...