Submission #83533

#TimeUsernameProblemLanguageResultExecution timeMemory
83533Noam527Paths (BOI18_paths)C++17
100 / 100
656 ms135916 KiB
#include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> #define endl '\n' #define fast ios::sync_with_stdio(0), cin.tie(0) #define debug cout << "ok" << endl #define finish(x) return cout << x << endl, 0 typedef long long ll; typedef long double ldb; const int md = 1e9 + 7, inf = 1e9 + 7; const ll hs = 199; const ldb eps = 1e-9, pi = acos(-1); using namespace std; int n, m, k; vector<int> c; vector<vector<int>> g; vector<ll> dp[32]; ll calc(int v, int mask) { if ((mask & (1 << c[v])) == 0) return 0; if (dp[mask][v] != -1) return dp[mask][v]; if (mask == (1 << c[v])) return dp[mask][v] = 1; dp[mask][v] = 0; for (const auto &i : g[v]) { dp[mask][v] += calc(i, mask ^ (1 << c[v])); } return dp[mask][v]; } int main() { fast; cin >> n >> m >> k; c.resize(n); for (auto &i : c) cin >> i, --i; g.resize(n); for (int i = 0, u, v; i < m; i++) { cin >> u >> v; --u, --v; g[u].push_back(v); g[v].push_back(u); } for (int i = 0; i < (1 << k); i++) dp[i].resize(n, -1); ll ans = 0; for (int i = 0; i < n; i++) for (int mask = 0; mask < (1 << k); mask++) if (mask != (mask & -mask)) ans += calc(i, mask); finish(ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...