Submission #473377

#TimeUsernameProblemLanguageResultExecution timeMemory
473377elgamalsalmanPaths (BOI18_paths)C++14
100 / 100
511 ms109732 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; ll dp[350050][32]; int n, m, k, colours[350050]; vvi adj; ll dfs(int u, int mask) { if (dp[u][mask] != -1) return dp[u][mask]; //cerr << "// dfs(" << u << ", " << mask << ")\n"; mask |= (1 << colours[u]); ll pathsCount = 0; for (int v : adj[u]) { if ((1 << colours[v]) & mask) continue; pathsCount += 1 + dfs(v, mask); } mask ^= (1 << colours[u]); dp[u][mask] = pathsCount; return dp[u][mask]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> k; adj.assign(n + 20, vi()); for (int i = 0; i < n; i++) { cin >> colours[i]; colours[i]--; } for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; adj[a].push_back(b); adj[b].push_back(a); } memset(dp, -1, sizeof dp); ll ans = 0; for (int i = 0; i < n; i++) { ans += dfs(i, 0); } cout << ans << '\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...