QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#506742#6430. Monster HunterTimeless123WA 0ms3696kbC++171.2kb2024-08-05 21:05:442024-08-05 21:05:44

Judging History

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

  • [2024-08-05 21:05:44]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3696kb
  • [2024-08-05 21:05:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 3e3 + 9;
const int mod = 1e9 + 7;
#define eps 1e-5
#define inf 1e18

ll f[N][N][2];
ll hp[N],p[N];
ll n;
vector<int> g[N];
int sz[N];

void dfs(int x)
{
	f[x][0][0] = 0;
	f[x][1][1] = hp[x];
	sz[x] = 0;

	for(auto &y:g[x])
	{
		dfs(y);

		for(int i = sz[x]; i >= 0;-- i) 
			for(int j = sz[y]; j >= 0; -- j)
			{
				f[x][i + j][1] = min(f[x][i + j][1], f[x][i][1] + min(f[y][j][0], f[y][j][1] + hp[y]));//拿根-->拿儿子时加上儿子权值
				f[x][i + j][0] = min(f[x][i + j][0], f[x][i][0] + min(f[y][j][0], f[y][j][1]));
			}

		sz[x] += sz[y];
	} 

}

void solve()
{
    cin>>n;
	for(int i = 1;i <= n; ++ i) g[i].clear(); 

	for(int i = 1;i <= n; ++ i) 
		for(int j = 0;j <= n; ++ j) f[i][j][1] = f[i][j][0] = inf;

	for(int i=2 ;i <= n;++ i) 
	{
		cin>>p[i];
		g[p[i]].push_back(i);
	}
	for(int i = 1;i <= n; ++ i) cin>>hp[i];

	dfs(1);

	for(int i = n;i >= 0; -- i)
	{
		cout<< min(f[1][i][1],f[1][i][0]) <<' ';
	}
	cout<<'\n';
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;  cin>>_;
    while (_--) solve();
    return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3696kb

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:

1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1 0 
1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 8 0 
1000000000000000000 1000000000000000000 1000000000...

result:

wrong answer 1st words differ - expected: '29', found: '1000000000000000000'