Dragonfly

아직 제출이 없습니다시간 제한5초메모리 제한1024 MB

문제

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. At pond ii (1in1 ≤ i ≤ n), there are b\[i]b\[i] bugs that the dragonflies can eat. The bugs at pond ii belong to species s\[i]s\[i].

Benson has also noted down n1n - 1 trails. Each trail jj (1j<n1 ≤ j < n) connects 2 distinct ponds u\[j]u\[j] and v\[j]v\[j] bidirectionally. 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 (1kd1 ≤ k ≤ d) has a home pond of h\[k]1h\[k] \ne 1 and will travel to pond h\[k]h\[k] without visiting any pond more than once using only the trails. These dragonflies will be released in increasing order from dragonfly 11 to dragonfly dd. After a dragonfly is released, it will eat a single bug (if there is one or more bugs remaining) at every pond that it visits (including pond 11), reducing the number of bugs at each of those ponds by 11 if it is not 00.

Help Benson determine the number of distinct species of bugs eaten during the journey of each of the dd dragonflies.

입력

The input format is as follows:

  • The first line of input contains 22 spaced integers nn and dd respectively.
  • The next line of input contains nn spaced integers b\[1],b\[2],,b\[n]b\[1], b\[2], \cdots , b\[n].
  • The next line of input contains nn spaced integers s\[1],s\[2],,s\[n]s\[1], s\[2], \cdots , s\[n].
  • The next line of input contains dd spaced integers h\[1],h\[2],,h\[d]h\[1], h\[2], \cdots , h\[d].
  • The next n1n - 1 lines of input contains 22 spaced integers each. The iith of these lines contains u\[i]u\[i] and v\[i]v\[i] respectively.

출력

Output a single line with dd spaced integers. The kkth of these integers should be the number of distinct species of bugs eaten by the kkth dragonfly.

제한

  • 2n21052 ≤ n ≤ 2 · 10^5
  • 1d21061 ≤ d ≤ 2 · 10^6
  • 1s\[i]n1 ≤ s\[i] ≤ n (for all 1in1 ≤ i ≤ n)
  • 0b\[i]d0 ≤ b\[i] ≤ d (for each 1in1 ≤ i ≤ n)
  • 1u\[j],v\[j]n1 ≤ u\[j], v\[j] ≤ n, u\[j]v\[j]u\[j] \ne v\[j] (for each 1jn11 ≤ j ≤ n - 1)
  • 2h\[k]n2 ≤ h\[k] ≤ n (for each 1kn1 ≤ k ≤ n)