#include<iostream>
#include<vector>
using namespace std;
int N, M, K;
long long dp[300'001][32]; // v, ilość = kod_bin
short kol[300'001];
vector<int>graf[300'001];
vector<pair<int, int>>mapuj[6][5]; // długość_składnika, kolory 1-5
// mapuj[ długość_składnika ][ kolor_v ] = { {x, x}, {x, x}, {x, x}, ... }
void inicjuj_mapowanie(){
int bity[32];
for(int i=0; i<32; i++)
bity[i] = (bool)(i&1) + (bool)(i&2) + (bool)(i&4) + (bool)(i&8) + (bool)(i&16);
for(int k = 1; k<=K; k++){
for(int d=1; d<K; d++){
// sprawdzam jakie bitmaski się nadają
for(int m=0; m<32; m++){
int b = 1<<(k-1);
// cout<<b<<' '<<bity[m]<<'\n';
if( (b&m)==0 && d == bity[m] ){
mapuj[d][k].push_back({m, m|b});
}
}
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>N>>M>>K;
for(int i=1; i<=N; i++){
cin>>kol[i];
dp[i][1<<(kol[i]-1)] = 1;
}
for(int i=1; i<=M; i++){
int a, b;
cin>>a>>b;
graf[a].push_back(b);
graf[b].push_back(a);
}
inicjuj_mapowanie();
long long suma = 0;
for(int d=2; d<=K; d++){
for(int v=1; v<=N; v++){
long long zyskane = 0;
for(int i:graf[v]){
for(auto j:mapuj[d-1][kol[v]]){
suma += dp[i][j.first];
dp[v][j.second] += dp[i][j.first];
//zyskane += dp[i][j.first];
}
}
//cout<<v<<": "<<zyskane<<'\n';
}
}
cout<<suma<<'\n';
}
// for(auto i:mapuj[3][2]){
// for(int j=0; j<5; j++)
// cout<<(bool)(i.first&(1<<j));
// cout<<" ";
// for(int j=0; j<5; j++)
// cout<<(bool)(i.second&(1<<j));
// cout<<'\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... |