Submission #392130

#TimeUsernameProblemLanguageResultExecution timeMemory
392130VictorPaths (BOI18_paths)C++17
100 / 100
475 ms98528 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = a; i < b; ++i) #define per(i, a, b) for (int i = b - 1; i >= a; --i) #define trav(a, x) for (auto& a : x) #define sz(a) a.size() #define umap unordered_map #define uset unordered_set typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; vi graph[300001]; ll memo[300001][32]; int colors[300001]; ll dp(int u, int mask) { ll& ans = memo[u][mask]; if (ans != -1) return ans; ans = 1; trav(v, graph[u])if(mask&(1<<colors[v]))ans+=dp(v,mask^(1<<colors[v])); return ans; } int main() { cin.tie(0)->sync_with_stdio(0); memset(memo, -1, sizeof(memo)); int n, m, k; cin >> n >> m >> k; rep(i, 0, n) { cin>>colors[i]; --colors[i]; graph[n].push_back(i); } rep(i, 0, m) { int u, v; cin >> u >> v; graph[--u].push_back(--v); graph[v].push_back(u); } cout<<dp(n, (1 << k) - 1) - n - 1<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...