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 int long long
#define endl '\n'
using namespace std;
const int N = 300001,INF=1e12;
int n , m , k , x , vis[N] , col[N] , ans;
int dp[N][(1<<5)+5];
vector<int>edges[N];
int dfs(int node , int mask){
if(dp[node][mask]!=-1){
return dp[node][mask];
}
dp[node][mask]=1;
for(auto e:edges[node]){
if(!((1<<col[e])&mask)){
dp[node][mask]+=dfs(e , mask|(1<<col[e]));
}
}
return dp[node][mask];
}
int32_t main()
{
//freopen("abc.in", "r", stdin);
memset(dp,-1,sizeof dp);
cin >> n >> m >> k ;
for(int i = 1 ; i <= n ; i ++){
cin >> x;
col[i]=x;
}
for(int i = 0 ; i < m ; i ++)
{
int u , v ;
cin >> u >> v;
edges[u].push_back(v);
edges[v].push_back(u);
}
for(int i = 1 ; i <= n ; i++)
{
ans+=dfs(i,1<<col[i]);
}
cout<<ans-n<<endl;
}
# | 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... |