Submission #775790

#TimeUsernameProblemLanguageResultExecution timeMemory
775790horiiseunPaths (BOI18_paths)C++17
0 / 100
58 ms26316 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; int n, m, k, colours[300005], dp[300005][35], ans; vector<int> adj[300005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> colours[i]; colours[i]--; dp[i][1 << colours[i]] = 1; } for (int i = 0, a, b; i < m; i++) { cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } for (int i = 2; i <= 5; i++) { vector<int> nxt; for (int j = 1; j < 32; j++) { if (__builtin_popcount(j) == i) { nxt.push_back(j); } } for (int j = 1; i <= n; j++) { for (int k : adj[j]) { for (int m : nxt) { if (m >> colours[j] & 1) { dp[j][m] += dp[k][m ^ (1 << colours[j])]; } } } } } for (int i = 1; i <= n; i++) { for (int j = 1; j < 32; 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...