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 pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, k; cin >> n >> m >> k;
vector<int> color(n);
for(int &x: color) cin >> x, x--;
vector<vector<int>> graph(n);
for(int i = 0; i < m; i++){
int a, b; cin >> a >> b; a--, b--;
graph[a].pb(b);
graph[b].pb(a);
}
vector<vector<ll>> dp(n, vector<ll>((1<<k), 0));
for(int i = 0; i < n; i++) dp[i][1<<color[i]] = 1;
for(int i = 0; i < (1<<k); i++){
if(__builtin_popcount(i) < 2) continue;
for(int j = 0; j < n; j++) if(i&(1<<color[j])){
for(int x: graph[j]) dp[j][i]+=dp[x][i^(1<<color[j])];
}
}
ll ans = 0;
for(int i = 0; i < (1<<k); i++) if(__builtin_popcount(i) > 1)
for(int j = 0; j < n; j++) ans+=dp[j][i];
cout << ans << "\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... |