Submission #418139

#TimeUsernameProblemLanguageResultExecution timeMemory
418139tengiz05Paths (BOI18_paths)C++17
100 / 100
2061 ms233796 KiB
#include <bits/stdc++.h> using i64 = long long; constexpr int N = 3e5 + 5; int n, m, k; int dp[6][N][32], a[N]; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cin >> n >> m >> k; for (int i = 0; i < n; i++) { std::cin >> a[i]; a[i]--; dp[0][i][1 << a[i]] = 1; } std::vector<std::pair<int, int>> e(m); for (auto &[u, v] : e) { std::cin >> u >> v; u--; v--; } for (int K = 1; K < 6; K++) { for (int msk = 1; msk < 32; msk++) { for (auto [u, v] : e) { if (!(msk & (1 << a[u])) || !(msk & (1 << a[v]))) continue; dp[K][u][msk] += dp[K - 1][v][msk ^ (1 << a[u])]; dp[K][v][msk] += dp[K - 1][u][msk ^ (1 << a[v])]; } } } i64 ans = 0; for (int K = 1; K < 6; K++) { for (int msk = 1; msk < 32; msk++) { for (int i = 0; i < n; i++) { ans += dp[K][i][msk]; } } } std::cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...