Submission #657732

#TimeUsernameProblemLanguageResultExecution timeMemory
657732inksamuraiPaths (BOI18_paths)C++17
100 / 100
744 ms64700 KiB
#include <bits/stdc++.h> #define int ll using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define rng(i,c,n) for(int i=c;i<n;i++) #define fi first #define se second #define pb push_back #define sz(a) (int)a.size() #define vec(...) vector<__VA_ARGS__> #define _3NRqilq ios::sync_with_stdio(0),cin.tie(0) typedef long long ll; using pii=pair<int,int>; using vi=vector<int>; void print(){cout<<'\n';} template<class h,class...t> void print(const h&v,const t&...u){cout<<v<<' ',print(u...);} signed main(){ _3NRqilq; int n,m,k; cin>>n>>m>>k; vi a(n); rep(i,n){ cin>>a[i]; } rep(i,n){ a[i]-=1; } vec(vi) adj(n); rep(i,m){ int u,v; cin>>u>>v; u-=1,v-=1; adj[u].pb(v); adj[v].pb(u); } vec(vi) dp(1<<k,vi(n)); rep(i,n)dp[1<<a[i]][i]=1; int ans=0; rep(msk,1<<k){ rep(v,n){ for(auto u:adj[v]){ if(msk>>a[u]&1) continue; int nmsk=msk|(1<<a[u]); dp[nmsk][u]+=dp[msk][v]; } } rep(v,n){ ans+=dp[msk][v]; } } print(ans-n); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...