Submission #104681

#TimeUsernameProblemLanguageResultExecution timeMemory
104681WLZPaths (BOI18_paths)C++17
100 / 100
1043 ms268152 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, k; cin >> n >> m >> k; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; a[i]--; } vector< vector<int> > g(n + 1); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } vector< vector< vector<long long> > > dp(k, vector< vector<long long> >(n + 1, vector<long long>(1 << k, 0))); for (int i = 1; i <= n; i++) { dp[0][i][1 << a[i]] = 1; } for (int i = 0; i < k - 1; i++) { for (int u = 1; u <= n; u++) { for (int mask = 0; mask < (1 << k); mask++) { if (dp[i][u][mask] == 0) { continue; } for (auto& v : g[u]) { if (mask & (1 << a[v])) { continue; } dp[i + 1][v][mask | (1 << a[v])] += dp[i][u][mask]; } } } } long long ans = 0; for (int i = 1; i < k; i++) { for (int u = 1; u <= n; u++) { for (int mask = 0; mask < (1 << k); mask++) { ans += dp[i][u][mask]; } } } 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...