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;
typedef long long ll;
typedef pair<int, int> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define lowbit(x) x&-x
const int maxn = 3e5 + 5;
vector<int> adj[maxn];
int c[maxn];
int n, m, k;
int dp[maxn][32];
signed main(void){
fastio;
cin>>n>>m>>k;
for(int i = 0; i < n; i++) cin>>c[i], c[i]--;
for(int i = 0; i < m; i++){
int a, b;
cin>>a>>b;
a--, b--;
adj[a].pb(b);
adj[b].pb(a);
}
for(int i = 0; i < n; i++) dp[i][(1 << c[i])] = 1;
int ans = 0;
for(int rd = 1; rd < k; rd++){
for(int i = 0; i < n; i++){
for(int mask = 0; mask < (1 << k); mask++){
if(__builtin_popcount(mask) != rd) continue;
if(!dp[i][mask]) continue;
for(auto x : adj[i]){
if(mask & (1 << c[x])) continue;
dp[x][mask | (1 << c[x])] += dp[i][mask];
}
}
}
}
for(int i = 0; i < n; i++){
for(int mask = 1; mask < (1 << k); mask++){
if(__builtin_popcount(mask) == 1) continue;
ans += dp[i][mask];
}
}
cout<<ans<<"\n";
}
# | 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... |