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 ll long long
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false)
#define inf LLONG_MAX
#define l first
#define r second
const int lmt=3e5+10;
vector<int>adj[lmt];
int main(){
fastio;
int n,m,k;
cin>>n>>m>>k;
ll dp[n+1][(1<<k)];
int col[n+1];
for(int i=1;i<=n;i++) cin>>col[i];
vector<int>T[k+1];
for(int i=0;i<(1<<k);i++){
int cnt=__builtin_popcount(i);
T[cnt].push_back(i);
}
for(int i=1;i<=m;i++){
int u,v;
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i=1;i<=n;i++){
for(int j=0;j<(1<<k);j++) dp[i][j]=0;
}
for(int i=1;i<=n;i++){
dp[i][(1<<(col[i]-1))]=1;
}
ll ans=0;
for(int j=2;j<=k;j++){
for(int i=1;i<=n;i++){
for(int v:adj[i]){
for(int val:T[j-1]){
if(val&(1<<(col[i]-1))) continue;
dp[i][val|(1<<(col[i]-1))]+=dp[v][val];
}
}
}
}
for(int i=1;i<=n;i++){
for(int j=2;j<=k;j++){
for(int val:T[j]){
ans+=dp[i][val];
}
}
}
cout<<ans<<endl;
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... |