Submission #510032

#TimeUsernameProblemLanguageResultExecution timeMemory
510032haxormanPaths (BOI18_paths)C++14
100 / 100
420 ms112356 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int mxN = 3e5 + 7; const int mxK = 39; int n, m, k, color[mxN], dp[mxN][mxK]; vector<int> graph[mxN]; void dfs(int u, int mask, int cnt) { if (dp[u][mask]) { return; } if (cnt > 1) { dp[u][mask] = 1; } for (auto v : graph[u]) { if (!(mask & (1 << color[v]))) { dfs(v, mask | (1 << color[v]), cnt + 1); dp[u][mask] += dp[v][mask | (1 << color[v])]; } } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> k; for (int u = 1; u <= n; ++u) { cin >> color[u]; color[u]--; } for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; graph[u].push_back(v); graph[v].push_back(u); } int ans = 0; for (int i = 1; i <= n; ++i) { dfs(i, (1 << color[i]), 1); ans += dp[i][(1 << color[i])]; } 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...