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 f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int nmax = 2000001;
ll dp[nmax][32];
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n, m; cin >> n >> m;
int k; cin >> k;
int col[n + 1];
for(int i = 1; i <= n; i++){
cin >> col[i];
col[i]--;
dp[i][(1 << col[i])] = 1;
}
vector <vector <int> >g(n + 1);
for(int i = 1; i <= m; i++){
int u, v; cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
for(int mask = 1; mask < (1 << k); mask++){
for(int i = 1; i <= n; i++){
if(mask & (1 << col[i])){
for(int to : g[i]){
dp[i][mask] += dp[to][mask ^ (1 << col[i])];
}
}
}
}
ll ans = 0;
for(int i = 1; i < 32; i++){
for(int v = 1; v <= n; v++){
ans += dp[v][i];
}
}
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... |