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 all(x) x.begin(),x.end()
int INF=1e18;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,m,k;cin>>n>>m>>k;
vector<int> c(n);
for(int i=0;i<n;i++){
cin>>c[i];
c[i]--;
}
vector<vector<int>> adj(n);
for(int i=0;i<m;i++){
int a,b;cin>>a>>b;a--;b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
vector<vector<int>> dp((1<<k),vector<int>(n));
for(int i=0;i<n;i++){
dp[(1<<c[i])][i]=1;
}
for(int i=1;i<(1<<k);i++){
for(int j=0;j<n;j++){
if(i&(1<<c[j])){
for(int e:adj[j]){
dp[i][j]+=dp[i^(1<<c[j])][e];
}
}
}
}
int ans=0;
for(int i=0;i<(1<<k);i++){
for(int j=0;j<n;j++){
ans+=dp[i][j];
}
}
cout<<ans-n<<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... |