QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#199087#6430. Monster HunterrsjWA 1ms3600kbC++141020b2023-10-03 20:56:492023-10-03 20:56:49

Judging History

你现在查看的是最新测评结果

  • [2023-10-03 20:56:49]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3600kb
  • [2023-10-03 20:56:49]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 2050;
#define int long long
struct edge {
	int to;
	edge *nex;
}*head[N];
void add(int u,int v) {
	edge *cur=new edge;
	cur->to=v;
	cur->nex=head[u];
	head[u]=cur;
}
int f[N][N][2],siz[N],a[N],n; //1 Destructed
void dfs(int u) {
	siz[u]=1;
	for(edge *cur=head[u];cur;cur=cur->nex) dfs(cur->to),siz[u]+=siz[cur->to];
	for(int i=0;i<=siz[u];i++) {
		f[u][i][0]=2*a[u];
		if(i) f[u][i][1]=0;
		for(edge *cur=head[u];cur;cur=cur->nex) {
			if(i) f[u][i][1]+=min(f[cur->to][i-1][0]-a[cur->to],f[cur->to][i-1][1]);
			f[u][i][0]+=min(f[cur->to][i][0],f[cur->to][i][1]);
		}
	}
}
void get() {
	int i,j,x; cin>>n; for(i=1;i<=n;i++) head[i]=0;
	for(i=2;i<=n;i++) cin>>x,add(x,i);
	for(i=1;i<=n;i++) cin>>a[i],siz[i]=0;
	for(i=0;i<=n;i++) for(j=0;j<=n;j++) f[i][j][0]=f[i][j][1]=1e13;
	dfs(1);
	for(i=0;i<=n;i++) cout<<min(f[1][i][0]-a[1],f[1][i][1])<<" \n"[i==n]; 
}
signed main() {
	int T; cin>>T;
	while(T--) get();
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3600kb

input:

3
5
1 2 3 4
1 2 3 4 5
9
1 2 3 4 3 4 6 6
8 4 9 4 4 5 2 4 1
12
1 2 2 4 5 3 4 3 8 10 11
9 1 3 5 10 10 7 3 7 9 4 9

output:

29 16 9 4 1 0
74 45 25 13 4 0 19999999999995 19999999999991 10000000000016 10000000000004
145 65 31 21 15 19999999999993 19999999999990 19999999999987 20000000000011 20000000000001 19999999999992 19999999999992 10000000000009

result:

wrong answer 8th words differ - expected: '47', found: '45'