# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
898753 | vjudge1 | Magic Tree (CEOI19_magictree) | C++17 | 1344 ms | 84272 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;
const int mxn=21;
int n,m,k,dp[mxn][1<<20],par[mxn],fru[mxn][mxn],sz;
vector<int>v[mxn];
void dfs(int z,int j){
for(auto i:v[z]){
if(!(j&(1<<i-1)))
dfs(i,j);
}
sz++;
}
int main(){
cin>>n>>m>>k;
for(int i=2;i<=n;i++){
cin>>par[i];
v[par[i]].push_back(i);
}
for(int i=1;i<=m;i++){
int d,x,y;
cin>>x>>d>>y;
fru[x][d]=y;
}
for(int i=1;i<=k;i++){
for(int j=1;j<(1<<n);j++){
sz=0;
dfs(1,j);
if(sz==n-__builtin_popcount(j)){//cout<<j<<" ";
dp[i][j]=dp[i-1][j];
for(int w=1;w<=n;w++){
if((j&(1<<w)) && !(j&(1<<par[w+1]-1))){
dp[i][j]=max(dp[i][j],dp[i][j-(1<<w)]+fru[w+1][i]);
}
}
}
}
}
int ans=0;
for(int j=1;j<(1<<n);j++){
ans=max(ans,dp[k][j]);
}
cout<<ans<<endl;
}
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... |
# | 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... |