Submission #1131525

#TimeUsernameProblemLanguageResultExecution timeMemory
1131525lopkusPaths (BOI18_paths)C++20
100 / 100
272 ms57884 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m, k; cin >> n >> m >> k; vector<int> a(n + 1); for(int i = 1; i <= n; i++) { cin >> a[i]; } vector<int> adj[n + 1]; for(int i = 1; i <= m; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } int dp[n + 1][1LL << k]; for(int i = 0; i <= n; i++) { for(int j = 0; j < 1LL << k; j++) { dp[i][j] = 0; } } for(int i = 1; i <= n; i++) { a[i] -= 1; dp[i][1LL << a[i]] = 1; } for(int j = 0; j < (1LL << k); j++) { for(int i = 1; i <= n; i++) { if(j & (1LL << a[i])) { continue; } for(auto it : adj[i]) { if(!(j & (1LL << a[it]))) { continue; } dp[i][j ^ (1LL << a[i])] += dp[it][j]; } } } int ans = 0; for(int i = 1; i <= n; i++) { for(int j = 0; j < 1LL << k; j++) { ans += dp[i][j]; } } 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...