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 mx=1e5+10;
typedef long long ll;
int mod=1e9+7;
const int MXm=22;
#define F first
#define S second
const int inf=1e9+10;
ll dp[mx][1<<5];
int c[mx];
vector<int>adj[mx];
int n,m,k;
ll solve(int node,int mask){
ll &ret=dp[node][mask];
if(ret!=-1){
return ret;
}
ret=1;
for(auto it:adj[node]){
if(!((1<<c[it])&mask)){
ret+=solve(it,mask|(1<<c[it]));
}
}
return ret;
}
int main(){
memset(dp,-1,sizeof(dp));
cin>>n>>m>>k;
for(int i=1;i<=n;i++){
cin>>c[i];
c[i]--;
}
ll ans=0;
for(int i=1;i<=m;i++){
int a,b;cin>>a>>b;
adj[a].push_back(b);
adj[b].push_back(a);
}
for(int i=1;i<=n;i++){
ans+=solve(i,1<<c[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... |