Submission #314414

#TimeUsernameProblemLanguageResultExecution timeMemory
314414TemmiePaths (BOI18_paths)C++17
100 / 100
1028 ms109176 KiB
#include <bits/stdc++.h> typedef long long ll; int cnt(int x) { int r = 0; while (x) { r += x & 1; x >>= 1; } return r; } int main() { std::ios::sync_with_stdio(0); std::cin.tie(0); int n, m, k; std::cin >> n >> m >> k; std::vector <int> col(n); std::vector <std::vector <ll>> dp(3e5 + 5, std::vector <ll> (32, 0)); for (int i = 0; i < n; i++) { std::cin >> col[i]; col[i]--; dp[i][1 << col[i]] = 1; } std::vector <std::vector <int>> g(n); for (int i = 0; i < m; i++) { int u, v; std::cin >> u >> v; u--, v--; g[u].push_back(v); g[v].push_back(u); } for (int i = 1; i < k; i++) for (int j = 0; j < n; j++) for (int l = 1; l < 32; l++) { if (cnt(l) != i) continue; for (int x : g[j]) if (!(l & (1 << col[x]))) dp[x][(l ^ (1 << col[x]))] += dp[j][l]; } ll ans = -n; for (int i = 0; i < n; i++) for (int j = 1; j < 32; j++) ans += dp[i][j]; std::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...