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;
#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 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... |