# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
792699 | 2023-07-25T08:10:31 Z | TheSahib | Paths (BOI18_paths) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> #define ll long long #define oo 1e9 #define pii pair<int, int> using namespace std; const int MAX = 1e5 + 5; int n, m, k; int color[MAX]; vector<int> g[MAX]; ll dp[MAX][1 << 5]; void solve(){ cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> color[i]; color[i]--; dp[i][1 << color[i]] = 1; } for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; g[v].push_back(u); g[u].push_back(v); } ll ans = 0; for (int mask = 1; mask < (1 << k); mask++) { if(__popcount(mask) <= 1) continue; for (int node = 1; node <= n; node++) { if(!(mask & (1 << color[node]))) continue; for(int to:g[node]){ dp[node][mask] += dp[to][mask ^ (1 << color[node])]; } ans += dp[node][mask]; } } cout << ans << '\n'; } int main() { solve(); }