# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
118562 | DystoriaX | Paths (BOI18_paths) | C++14 | 839 ms | 97528 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int col[300010];
vector<int> adj[300010];
long long dp[300010][1 << 5], ans;
int main() {
scanf("%d%d%d", &n, &m, &k);
for(int i = 1; i <= n; i++) scanf("%d", &col[i]), col[i]--;
while(m--){
int u, v;
scanf("%d%d", &u, &v);
adj[u].emplace_back(v);
adj[v].emplace_back(u);
}
for(int i = 1; i <= n; i++) dp[i][1 << col[i]] = 1;
for(int len = 2; len <= k; len++){
for(int i = 1; i <= n; i++){
for(int mask = 0; mask < (1 << k); mask++){
if(__builtin_popcount(mask) != len - 1) continue;
for(auto v : adj[i]){
if(!(mask & (1 << col[v]))){
dp[v][mask | (1 << col[v])] += dp[i][mask];
}
}
}
}
}
for(int i = 1; i <= n; i++)
for(int mask = 0; mask < (1 << k); mask++)
if(__builtin_popcount(mask) > 1) ans += dp[i][mask];
printf("%lld\n", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |