Submission #93703

#TimeUsernameProblemLanguageResultExecution timeMemory
93703KLPPPaths (BOI18_paths)C++14
100 / 100
795 ms113796 KiB
#include<bits/stdc++.h> using namespace std; typedef long long int lld; int n,m,k; vector<int> nei[1000000]; int color[1000000]; lld DP[1000000][32]; lld compute(int pos, int msk){ if(DP[pos][msk]!=-1)return DP[pos][msk]; int c=color[pos]; int Bit=msk&(1<<c); if(Bit==0){ DP[pos][msk]=0; return 0; } DP[pos][msk]=0; for(int i=0;i<nei[pos].size();i++){ DP[pos][msk]+=compute(nei[pos][i],msk-(1<<c)); } return DP[pos][msk]; } int main(){ cin>>n>>m>>k; for(int i=0;i<n;i++){ cin>>color[i]; color[i]--; } for(int i=0;i<m;i++){ int x,y; cin>>x>>y; x--; y--; nei[x].push_back(y); nei[y].push_back(x); } for(int i=0;i<n;i++){ for(int msk=0;msk<32;msk++)DP[i][msk]=-1; DP[i][(1<<color[i])]=1; } lld ans=0; for(int i=0;i<n;i++){ for(int msk=1;msk<(1<<k);msk++){ans+=compute(i,msk); //cout<<compute(i,msk)<<" "; }//cout<<endl; } ans-=n; cout<<ans<<endl; return 0; }

Compilation message (stderr)

paths.cpp: In function 'lld compute(int, int)':
paths.cpp:18:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<nei[pos].size();i++){
              ~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...