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>
#define DEBUG 0
using namespace std;
const int MAX_N = 3e5 + 10;
const int MAX_K = 5;
int a[MAX_N], b[MAX_N], c[MAX_N];
long long dp[MAX_N][1<<MAX_K];
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, M, K;
cin >> N >> M >> K;
for(int i = 1; i <= N; i++) {
cin >> c[i];
c[i]--;
dp[i][1<<c[i]] = 1;
}
for(int i = 1; i <= M; i++) {
cin >> a[i] >> b[i];
}
long long ans = 0;
for(int mask = 1; mask < (1<<K); mask++) {
if(__builtin_popcount(mask) == 1) {
continue;
}
for(int i = 1; i <= M; i++) {
if(mask & (1<<c[a[i]])) {
dp[a[i]][mask] += dp[b[i]][mask ^ (1<<c[a[i]])];
}
if(mask & (1<<c[b[i]])) {
dp[b[i]][mask] += dp[a[i]][mask ^ (1<<c[b[i]])];
}
}
for(int i = 1; i <= N; i++) {
ans += dp[i][mask];
}
}
cout << ans;
return 0;
}
# | 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... |