Under construction

Still being built. Things may change

My Lion Paintings

Time limit3sMemory limit1024 MB

Summary
For each room as the work room, find the maximum number of paintings you can repair within time M, where each repair costs C_i plus its distance to that room.
Level

Hard9 of 10

Topics
Tree, Dynamic programming, Greedy
Solved
No attempts yet

Problem

I painted lion pictures and displayed them in a museum shaped like a tree. The museum has several rooms connected by passages, and each room holds one painting. If the rooms are vertices and the passages are edges, the graph is a tree. Room 1 is the root, and it has the door where visitors enter and leave.

Someone broke in and made every lion painting look like a bear. I painted exactly N lion paintings, and there are K kinds of them. Repairing one painting of kind i takes CiC_i time. Paint is limited, so at most PiP_i paintings of kind i can be repaired.

Root the tree at room 1 and pick one room as the work room. You can repair only the paintings in the subtree rooted at the work room. Each time you finish a job you must return to the work room, so if a painting is at distance d from the work room, the job costs an extra d time. You can work for M time in total. For each room chosen as the work room, find the maximum number of paintings you can repair so that the total work time does not exceed M.

Input

The first line contains N, K, and M. (1≤K≤N≤2×1051 \le K \le N \le 2 \times 10^5, 1≤M≤10151 \le M \le 10^{15})

The next N-1 lines describe the passages. The i-th line contains the number of the parent room of room i+1 and the distance from that parent room, separated by a space. (1≤1 \le passage length ≤105\le 10^5)

The next line contains N numbers, where the i-th number is the kind of painting in room i. (1≤1 \le painting kind ≤K\le K)

The next line contains K numbers, where the i-th number is CiC_i. (1≤Ci≤M1 \le C_i \le M)

The next line contains K numbers, where the i-th number is PiP_i. (1≤Pi≤N1 \le P_i \le N)

Output

On the i-th line, print the maximum number of paintings you can repair when room i is the work room.

Examples1

  1. Example 1

    Input
    12 4 10
    1 1
    1 1
    1 2
    2 3
    5 7
    2 4
    5 1
    3 10
    4 2
    4 3
    9 5
    1 2 1 3 1 4 2 4 3 2 1 2
    1 1 1 1
    1 1 1 1
    Expected output
    3
    3
    1
    3
    2
    1
    1
    1
    2
    1
    1
    1