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 MAX = 3e5 + 10 ;
int arr[MAX] ;
int n , m , k ;
vector< vector<int> >adj(MAX) ;
long long dp[MAX][64] ;
void dfs(int node , int mask)
{
if(dp[node][mask])
return ;
dp[node][mask] = 1 ;
for(auto &child : adj[node])
{
if((mask & (1 << arr[child])))
continue ;
dfs(child , mask | (1 << arr[child])) ;
dp[node][mask] += dp[child][mask | (1 << arr[child])] ;
}
}
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n>>m>>k ;
for(int i = 1 ; i <= n ; ++i)
{
cin>>arr[i] ;
arr[i]-- ;
}
for(int i = 0 ; i < m ; ++i)
{
int x , y ;
cin>>x>>y ;
adj[x].push_back(y) ;
adj[y].push_back(x) ;
}
long long ans = 0 ;
for(int i = 1 ; i <= n ; ++i)
{
dfs(i , (1 << arr[i])) ;
ans += dp[i][(1 << arr[i])] - 1 ;
}
return cout<<ans<<"\n" , 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... |