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
const int N = 3e5 + 5;
const int K = 5;
vector<int> g[N];
int dp[N][(1 << K)] , C[N] , ans , n , m , k;
int32_t main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m >> k;
for(int i = 1 ; i <= n ; i++){
cin >> C[i];
C[i]--;
dp[i][(1 << C[i])] = 1;
}
for(int i = 1 ; i <= m ; i++){
int u , v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
for(int mask = 1 ; mask < (1 << K) ; mask++){
if(__builtin_popcount(mask) == 1) continue;
for(int i = 1 ; i <= n ; i++){
if(mask & (1 << C[i])){
for(int j : g[i])
dp[i][mask] += dp[j][mask ^ (1 << C[i])];
ans += dp[i][mask];
}
}
}
cout << ans << '\n';
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... |