Submission #967734

#TimeUsernameProblemLanguageResultExecution timeMemory
967734mannshah1211Paths (BOI18_paths)C++17
100 / 100
373 ms70736 KiB
/** * author: hashman * created: **/ #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "algo/debug.h" #else #define debug(...) 42 #endif int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, k; cin >> n >> m >> k; vector<int> c(n); for (int i = 0; i < n; i++) { cin >> c[i]; --c[i]; } vector<vector<int>> g(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; --a; --b; g[a].push_back(b); g[b].push_back(a); } vector<vector<int64_t>> dp(n, vector<int64_t>(1 << k)); for (int i = 0; i < n; i++) { dp[i][1 << c[i]] = 1; } for (int j = 1; j < (1 << k); j++) { for (int i = 0; i < n; i++) { if (j & (1 << c[i])) { for (int prv : g[i]) { dp[i][j] += dp[prv][j - (1 << c[i])]; } } } } int64_t ans = 0; for (int i = 0; i < n; i++) { for (int j = 1; j < (1 << k); j++) { ans += dp[i][j]; } } cout << ans - n << '\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...