# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
121012 | IOrtroiii | Paths (BOI18_paths) | C++14 | 357 ms | 33132 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;
using ll = long long;
const int N = 100100;
const int K = 5;
int n, m, k;
int a[N];
vector<int> g[N];
ll f[N][1 << K];
int main() {
scanf("%d %d %d", &n, &m, &k);
for (int i = 1; i <= n; ++i) {
scanf("%d", a + i);
--a[i];
}
for (int i = 1; i <= m; ++i) {
int u, v;
scanf("%d %d", &u, &v);
g[u].push_back(v);
g[v].push_back(u);
}
for (int i = 1; i <= n; ++i) {
f[i][1 << a[i]] = 1ll;
}
ll ans = 0;
for (int mask = 1; mask < (1 << k); ++mask) {
for (int i = 1; i <= n; ++i) {
ans += f[i][mask];
for (int j : g[i]) {
if (!(mask & (1 << a[j]))) {
f[j][mask | (1 << a[j])] += f[i][mask];
}
}
}
}
printf("%lld\n", ans - n);
}
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... |