Блог пользователя RikiSabe

Автор RikiSabe, история, 8 месяцев назад, По-английски

Hi all, I have a question about queries on a tree.

You are given a tree and each node has a value, for each node 'u' you should count the number of nodes 'v' that exist in the subtree of node u with the same value than 'u'.

Input An integer n (n <= 10^5) the number of nodes in the tree Each of the next n — 1 lines describes and edge on the tree The last line consists of n integers the a_i (-10^5 <= a_i <= 10^5) the value for the node i (1, 2,... n)

Output n integers with the answer for the i-th node

EXAMPLE

INPUT:

9

1 3

3 5

3 4

1 2

2 6

2 7

7 8

7 9

5 2 -1 -1 5 5 -1 2 -1

OUTPUT

2 1 1 0 0 0 1 0 0

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится