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;
const int maxn = 1e5 + 10;
vector <int> adj[maxn];
int dp[maxn][32];
int c[maxn];
int n, m , k;
int main(){
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++){
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
long long ans = 0;
for(int mask = 1; mask < (1 << k); mask++){
if(__builtin_popcount(mask) == 1) continue;
for(int i = 1; i <= n; i++){
if(mask & (1 << c[i])){
for(int u : adj[i]){
dp[i][mask] += dp[u][mask ^ (1 << c[i])];
}
ans += dp[i][mask];
}
}
}
cout << ans << 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... |