QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#209012 | #6430. Monster Hunter | HT008 | Compile Error | / | / | C++14 | 1.1kb | 2023-10-10 02:29:31 | 2023-10-10 02:29:32 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxm=2e3+100;
vector<int> edge[maxm];
int dp[maxm][maxm][2],val[maxm],siz[maxm];
int n;
void dfs(int now)
{
siz[now]=1;
dp[now][0][0]=0;
dp[now][1][1]=val[now];
for(int i=0;i<edge[now].size();i++)
{
int v=edge[now][i];
dfs(v);
for(int j=siz[now];j>=0;j--)
for(int k=siz[v];k>=0;k--)
{
dp[now][j+k][0]=min(dp[now][j+k][0],dp[now][j][0]+min(dp[v][k][0],dp[v][k][1]));
dp[now][j+k][1]=min(dp[now][j+k][1],dp[now][j][1]+min(dp[v][k][0],dp[v][k][1]+val[v]));
}
siz[now]+=siz[v];
}
}
void init()
{
memset(dp,127/3,sizeof(dp));
for(int i=1;i<=n;i++)
edge[i].clear();
}
void work()
{
scanf("%d",&n);
init();
for(int i=2;i<=n;i++)
{
int x;
scanf("%d",&x);
edge[x].push_back(i);
}
for(int i=1;i<=n;i++)
scanf("%d",&val[i]);
dfs(1);
for(int i=n;i>=0;i--)
printf("%d ",min(dp[1][i][1],dp[1][i][0]));
puts("");
}
int main()
{
int t;
scanf("%d",&t);
while(t--) work();
return 0;
}
Details
answer.code:7:1: error: ‘vector’ does not name a type 7 | vector<int> edge[maxm]; | ^~~~~~ answer.code: In function ‘void dfs(int)’: answer.code:15:23: error: ‘edge’ was not declared in this scope 15 | for(int i=0;i<edge[now].size();i++) | ^~~~ answer.code: In function ‘void init()’: answer.code:32:17: error: ‘edge’ was not declared in this scope 32 | edge[i].clear(); | ^~~~ answer.code: In function ‘void work()’: answer.code:43:17: error: ‘edge’ was not declared in this scope 43 | edge[x].push_back(i); | ^~~~ answer.code:37:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 37 | scanf("%d",&n); | ~~~~~^~~~~~~~~ answer.code:42:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 42 | scanf("%d",&x); | ~~~~~^~~~~~~~~ answer.code:46:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 46 | scanf("%d",&val[i]); | ~~~~~^~~~~~~~~~~~~~ answer.code: In function ‘int main()’: answer.code:55:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 55 | scanf("%d",&t); | ~~~~~^~~~~~~~~