Submission #94326

#TimeUsernameProblemLanguageResultExecution timeMemory
94326dalgerokPaths (BOI18_paths)C++14
100 / 100
520 ms99576 KiB
#include<bits/stdc++.h> using namespace std; const int N = 3e5 + 5, M = (1 << 5) + 1; int n, m, k, a[N]; vector < int > g[N]; long long dp[M][N]; long long rec(int mask, int v){ if(dp[mask][v] != -1){ return dp[mask][v]; } dp[mask][v] = 1; for(int to : g[v]){ if(!((mask >> a[to]) & 1)){ dp[mask][v] += rec((mask | (1 << a[to])), to); } } return dp[mask][v]; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n >> m >> k; for(int i = 1; i <= n; i++){ cin >> a[i]; a[i] -= 1; } for(int i = 1; i <= m; i++){ int x, y; cin >> x >> y; g[x].push_back(y); g[y].push_back(x); } long long ans = 0; memset(dp, -1, sizeof(dp)); for(int i = 1; i <= n; i++){ ans += rec((1 << a[i]), i); } 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...