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 <iostream>
#include <vector>
using namespace std;
const int nmax = 3e5;
const int kmax = 5;
long long dp[nmax][1 << kmax];
/// numarul de lanturi care se termina in i si am trecut prin bitii mask
int c[nmax];
vector < int > g[nmax + 1];
int main() {
int n, m, k, a, b;
cin >> n >> m >> k;
for ( int i = 0; i < n; i++ ) {
cin >> c[i];
c[i]--;
dp[i][1 << c[i]] = 1;
}
for ( int i = 0; i < m; i++ ) {
cin >> a >> b;
a--; b--;
g[a].push_back ( b );
g[b].push_back ( a );
}
for ( int mask = 1; mask < ( 1 << k ); mask++ )
for ( int i = 0; i < n; i++ )
for ( int node: g[i] )
if ( ! ( mask & ( 1 << c[node] ) ) )
dp[node][mask | ( 1 << c[node] )] += dp[i][mask];
long long s = 0;
for ( int mask = 1; mask < ( 1 << k ); mask++ )
if ( mask & ( mask - 1 ) )
for ( int i = 0; i < n; i++ )
s = s + dp[i][mask];
cout << s;
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... |