Submission #792702

#TimeUsernameProblemLanguageResultExecution timeMemory
792702TheSahibPaths (BOI18_paths)C++17
53 / 100
201 ms56984 KiB
#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(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...