Under construction

Still being built. Things may change

For Programming Excellence

Time limit8sMemory limit512 MB

Summary
Given a prerequisite tree of skills with level caps and importance weights, find the maximum sum of level times importance within a tuition budget.
Level

Medium7 of 10

Topics
Dynamic programming, Tree
Solved
No attempts yet

Problem

A programmer needs countless skills to become excellent. Each skill has its own importance degree, and the total programming competence is the sum of the products of each skill's level and its importance degree.

This summer, you plan to attend a summer programming school. The school offers courses for many of these skills. When you take a course for a skill, its level rises in proportion to the tuition you pay, one level per one yen. Each skill has an upper limit on its level, and spending more on it does not raise the level past that limit. Skills depend on one another. Except for the most basic course, a course for a skill requires that its prerequisite skill be at least a certain level.

You want the highest possible programming competence within your tuition budget.

Input

The input consists of no more than 100 datasets, each in the following format.

n k
h1 ... hn
s1 ... sn
p2 ... pn
l2 ... ln

The first line has two integers, nn, the number of skills (2≤n≤1002 \le n \le 100), and kk, the tuition budget (1≤k≤1051 \le k \le 10^5). Skills are numbered 1 through nn.

The second line has nn integers h1…hnh_1 \dots h_n. hih_i is the maximum level of skill ii, between 1 and 10510^5 inclusive.

The third line has nn integers s1…sns_1 \dots s_n. sis_i is the importance degree of skill ii, between 1 and 10910^9 inclusive.

The fourth line has n−1n-1 integers p2…pnp_2 \dots p_n. pip_i is the prerequisite skill of skill ii, between 1 and i−1i-1 inclusive. Skill 1 has no prerequisite.

The fifth line has n−1n-1 integers l2…lnl_2 \dots l_n. lil_i is the least level of prerequisite skill pip_i required to learn skill ii, between 1 and hpih_{p_i} inclusive.

The end of the input is a line containing two zeros.

Output

For each dataset, output one line containing a single integer: the highest programming competence measure achievable, that is, the maximum sum of the products of levels and importance degrees of the skills, within the given tuition budget. All skills start at level zero. You do not have to use up the whole budget.

Examples1

  1. Example 1

    Input
    3 10
    5 4 3
    1 2 3
    1 2
    5 2
    5 40
    10 10 10 10 8
    1 2 3 4 5
    1 1 2 3
    10 10 10 10
    5 10
    2 2 2 5 2
    2 2 2 5 2
    1 1 2 2
    2 1 2 1
    0 0
    
    Expected output
    18
    108
    35