Submission #1084728

#TimeUsernameProblemLanguageResultExecution timeMemory
1084728f0rizenPaths (BOI18_paths)C++17
100 / 100
219 ms61268 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9 + 7; const ll infll = 1e18; template<typename T> istream &operator>>(istream &is, vector<T> &a) { for (auto &i : a) { is >> i; } return is; } int bit(int mask, int i) { return (mask >> i) & 1; } int32_t main() { #ifdef LOCAL freopen("/tmp/input.txt", "r", stdin); #else ios::sync_with_stdio(false); cin.tie(nullptr); #endif int n, m, k; cin >> n >> m >> k; vector<int> c(n); cin >> c; for (auto &i : c) { --i; } vector<vector<int>> g(n); for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; --u, --v; g[u].push_back(v); g[v].push_back(u); } vector<vector<ll>> dp(1 << k, vector<ll>(n)); for (int i = 0; i < n; ++i) { dp[1 << c[i]][i] = 1; } for (int mask = 0; mask < (1 << k); ++mask) { for (int i = 0; i < n; ++i) { if (!bit(mask, c[i])) { continue; } for (auto j : g[i]) { if (!bit(mask, c[j])) { dp[mask ^ (1 << c[j])][j] += dp[mask][i]; } } } } ll sum = 0; for (int mask = 0; mask < (1 << k); ++mask) { for (int i = 0; i < n; ++i) { sum += dp[mask][i]; } } cout << sum - n << "\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...