Dragonfly | 프로그래밍의 벗 PivotOJ
PivotOJ

Dragonfly

시간 제한: 5000ms메모리 제한: 1024MB출처: NOI 2022 QualificationBOJ 27287

문제

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 (1 ≤ 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 (1 &le; 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 (1 &le; k &le; 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.

예제

예제 1

입력
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
출력
2 1 2 1 1 0

예제 2

입력
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
출력
2 1 1 1
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.