Submission #1118790

#TimeUsernameProblemLanguageResultExecution timeMemory
1118790imarnPaths (BOI18_paths)C++14
100 / 100
468 ms97328 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...