# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
66597 | Bruteforceman | Paths (BOI18_paths) | C++11 | 726 ms | 183732 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 k;
vector <int> g[300010];
int col[300010];
long long M[1 << 5][300010];
long long dp(int mask, int node) {
if(M[mask][node] != -1) return M[mask][node];
long long ans = 1;
for(auto i : g[node]) {
if((mask >> col[i]) & 1) {}
else {
ans += dp(mask ^ (1 << col[i]), i);
}
}
return M[mask][node] = ans;
}
int main(int argc, char const *argv[])
{
int n, m;
scanf("%d %d %d", &n, &m, &k);
for(int i = 1; i <= n; i++) {
scanf("%d", &col[i]);
--col[i];
}
for(int i = 0; i < m; i++) {
int p, q;
scanf("%d %d", &p, &q);
g[p].push_back(q);
g[q].push_back(p);
}
memset(M, -1, sizeof M);
long long ans = 0;
for(int i = 1; i <= n; i++) {
ans += dp(1 << col[i], i);
}
printf("%lld\n", ans - n);
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... |