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 int long long
#define sp << ' ' <<
#define nl << '\n'
vector<vector<int>> g;
signed main(){
cin.tie(0)->sync_with_stdio(0);
int n, m, k, x, y; cin >> n >> m >> k;
int c[n];
for(int i=0; i<n; ++i) cin >> c[i], c[i] = (1<<(c[i]-1));
g.resize(n);
while(m--){
cin >> x >> y; --x, --y;
g[x].push_back(y);
g[y].push_back(x);
}
int ans = 0;
int dp[n][1<<k];
for(int i=0; i<n; ++i){
fill(dp[i], dp[i]+(1<<k), 0LL);
dp[i][c[i]] = 1;
}
for(int cnt=1; cnt<k; ++cnt){
for(int u=0; u<n; ++u) for(int v : g[u]){
for(int i=0; i<(1<<k); ++i){
if(i&c[u]) continue;
int s=0;
for(int j=0; j<k; ++j)
if(i&(1<<j)) ++s;
if(s!=cnt) continue;
dp[u][c[u]|i] += dp[v][i];
ans += dp[v][i];
}
}
}
cout << ans;
}
# | 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... |