Submission #572235

#TimeUsernameProblemLanguageResultExecution timeMemory
572235hoanghq2004Paths (BOI18_paths)C++14
100 / 100
347 ms59612 KiB
#include <bits/stdc++.h> using namespace std; int n, m, k; int c[300010]; int f[300010][1 << 5]; vector <int> adj[300010]; long long res; int main() { ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m >> k; for (int i = 1; i <= n; ++i) { cin >> c[i]; --c[i]; } for (int i = 1; i <= m; ++i) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } for (int mask = 1; mask < (1 << k); ++mask) { if (__builtin_popcount(mask) == 1) { int cl = __builtin_ctz(mask); for (int u = 1; u <= n; ++u) if (cl == c[u]) f[u][mask] = 1; } else { for (int u = 1; u <= n; ++u) { if (!((mask >> c[u]) & 1)) continue; for (auto v: adj[u]) { if (c[u] == c[v]) continue; f[u][mask] += f[v][mask ^ (1 << c[u])]; } } } } for (int mask = 1; mask < (1 << k); ++mask) { if (__builtin_popcount(mask) == 1) continue; for (int u = 1; u <= n; ++u) res += f[u][mask]; } cout << res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...