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;
typedef long long ll;
ll dp[300001][1 << 6];
int a[300001], n, m, k;
vector <int> adj[300001];
ll ans (int pos, int mask) {
ll &ret = dp[pos][mask];
if (ret != -1) return ret;
ret = 1;
for (auto j : adj[pos]) {
if (!((mask >> a[j]) & 1)) {
ret += ans(j, mask ^ (1 << a[j]));
}
}
return ret;
}
int main () {
memset(dp, -1, sizeof(dp));
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i]; a[i]--;
}
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
ll sum = 0;
for (int i = 1; i <= n; i++) {
sum += ans(i, 1 << a[i]);
}
sum -= n;
cout << sum << '\n';
}
# | 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... |