# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
93703 | KLPP | Paths (BOI18_paths) | C++14 | 795 ms | 113796 KiB |
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>
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)
# | 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... |