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 ll long long
#define pb push_back
using namespace std;
const int N = 3e5 + 5;
ll dp[37][N];
int c[N];
vector <int> v[N];
signed main(){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n,m,k;
cin>>n>>m>>k;
for (int i = 1; i <= n; i++){
cin>>c[i];
--c[i];
dp[(1<<c[i])][i] = 1;
}
for (int i = 1; i <= m; i++){
int a,b;
cin>>a>>b;
v[a].pb(b);
v[b].pb(a);
}
for (int mask = 0; mask < (1<<k); mask++){
for (int i = 1; i <= n; i++){
if (dp[mask][i] && (mask & (1<<c[i])) > 0) {
for (int to: v[i]){
if (!(mask & (1<<c[to]))){
dp[mask ^ (1<<c[to])][to] += dp[mask][i];
}
}
}
}
}
ll ans=0;
for (int i = 1; i <= n; i++){
for (int mask = 0; mask < (1<<k); mask++){
if ((mask & (1<<c[i])) > 0 && __builtin_popcount(mask) > 1)
ans += dp[mask][i];
}
}
cout<<ans;
}
# | 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... |