Submission #1092800

#TimeUsernameProblemLanguageResultExecution timeMemory
1092800juicyPaths (BOI18_paths)C++17
100 / 100
240 ms70776 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif int main() { ios::sync_with_stdio(false); cin.tie(nullptr); 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); while (m--) { int u, v; cin >> u >> v; --u, --v; g[u].push_back(v); g[v].push_back(u); } long long res = 0; vector dp(n, vector<long long>(1 << k)); for (int i = 0; i < n; ++i) { dp[i][1 << c[i]] = 1; } for (int m = 1; m < 1 << k; ++m) { for (int i = 0; i < n; ++i) { if (dp[i][m]) { for (int j : g[i]) { if (!(m >> c[j] & 1)) { dp[j][m + (1 << c[j])] += dp[i][m]; } } if (__builtin_popcount(m) > 1) { res += dp[i][m]; } } } } cout << res; 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...