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 pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define szz(r) (ll)r.size()
#define vi vector<int>
#define vvi vector<vi>
#define pp pair<ll,int>
#define ub(x,i) upper_bound(all(x),i)-x.begin()
using namespace std;
const int mxn=3e5+5;
ll dp[mxn][32]{0};
vector<int>g[mxn];
int a[mxn];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,m,k;cin>>n>>m>>k;
for(int i=1;i<=n;i++)cin>>a[i],a[i]--;
for(int i=1;i<=m;i++){
int a,b;cin>>a>>b;g[a].pb(b);g[b].pb(a);
}
for(int i=1;i<=n;i++)dp[i][(1<<a[i])]=1;
for(int msk=1;msk<(1<<k);msk++){
for(int i=1;i<=n;i++){
if(!(msk&(1<<a[i])))continue;
for(auto v:g[i]){
dp[i][msk]+=dp[v][msk^(1<<a[i])];
}
}
}ll rs=0;
bool vis[32]={0};
vis[1]=vis[2]=vis[4]=vis[8]=vis[16]=1;
for(int msk=1;msk<(1<<k);msk++)for(int i=1;i<=n;i++)if(!vis[msk])rs+=dp[i][msk];
cout<<rs;
}
# | 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... |