Under construction

Still being built. Things may change

Dragonfly

Time limit5sMemory limit1024 MB

Summary
Each dragonfly flies along the unique tree path from pond 1 to its home pond, eating one bug per pond; count the distinct species it eats.
Level

Hard8 of 10

Topics
Tree, DFS, Hash map
Solved
No attempts yet

Statement

Dragonflies can be seen around ponds at Botanic Gardens and Bishan Park. In one of the denser forested areas, Benson the Rabbit has noted down nn ponds that the dragonflies fly around. Pond ii (1≤i≤n1 ≤ i ≤ n) has bib_i bugs that the dragonflies can eat. The bugs at pond ii belong to species sis_i.

Benson has also noted down n−1n-1 trails. Trail jj (1≤j<n1 ≤ j < n) connects two distinct ponds uju_j and vjv_j in both directions. Dragonflies can travel from any pond to any other pond using only the trails.

Benson has captured dd dragonflies and intends to release them one at a time at pond 11. Dragonfly kk (1≤k≤d1 ≤ k ≤ d) has a home pond hk≠1h_k \ne 1 and travels to pond hkh_k without visiting any pond more than once, using only the trails. The dragonflies are released in increasing order, from dragonfly 11 to dragonfly dd. After a dragonfly is released, it eats one bug at every pond it visits, including pond 11. The count at each of those ponds drops by 11 if it is not 00.

Help Benson determine the number of distinct species of bugs eaten by each dragonfly during its journey.

Input

The first line contains two space-separated integers nn and dd. The next line contains nn space-separated integers b1,b2,⋯ ,bnb_1, b_2, \cdots, b_n. The next line contains nn space-separated integers s1,s2,⋯ ,sns_1, s_2, \cdots, s_n. The next line contains dd space-separated integers h1,h2,⋯ ,hdh_1, h_2, \cdots, h_d. Each of the next n−1n-1 lines contains two space-separated integers, where the iith of these lines contains uiu_i and viv_i.

Output

Output a single line with dd space-separated integers. The kkth integer is the number of distinct species of bugs eaten by dragonfly kk.

Constraints

  • 2≤n≤2⋅1052 ≤ n ≤ 2 \cdot 10^5
  • 1≤d≤2⋅1061 ≤ d ≤ 2 \cdot 10^6
  • 1≤si≤n1 ≤ s_i ≤ n (for all 1≤i≤n1 ≤ i ≤ n)
  • 0≤bi≤d0 ≤ b_i ≤ d (for each 1≤i≤n1 ≤ i ≤ n)
  • 1≤uj,vj≤n1 ≤ u_j, v_j ≤ n, uj≠vju_j \ne v_j (for each 1≤j≤n−11 ≤ j ≤ n-1)
  • 2≤hk≤n2 ≤ h_k ≤ n (for each 1≤k≤n1 ≤ k ≤ n)

Examples2

  1. Example 1

    Input
    5 6
    4 1 0 3 1
    1 3 2 2 1
    2 5 4 3 4 2
    5 2
    2 1
    1 4
    1 3
    
    Expected output
    2 1 2 1 1 0
    
  2. Example 2

    Input
    7 4
    0 2 4 4 0 1 3
    6 1 6 2 2 2 1
    7 5 2 4
    4 1
    4 5
    6 2
    1 6
    1 3
    6 7
    
    Expected output
    2 1 1 1