output_description: Print the answers for k = 1, 2, ..., N in order, each in its own line.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      c_1 c_2 ... c_N
      a_1 b_1
      :
      a_{N-1} b_{N-1}
attempt: from copy import deepcopy
  
  n = int(input())
  col = list(map(int, input().split()))
  children = [[] for i in range(n)]
  n_path = [0] * n
  c_path = [[0] * n for i in range(n)]
  checked = [False] * n
  num_check = 0
  is_inv = False
  for i in range(n):
      col[i] -= 1
  for i in range(n - 1):
      a, b = map(int, input().split())
      children[a - 1].append(b - 1)
  for i in children:
      for j in range(len(i)):
          if checked[j]:
              is_inv = True
              break
          checked[j] = True
  if is_inv:
      tmp_children = deepcopy(children)
      children = [[] for i in range(n)]
      for i in range(n):
          for j in range(len(tmp_children[i])):
              children[tmp_children[i][j]].append(i)
  checked = [False] * n
  while num_check < n:
      for parent in range(n):
          if checked[parent]:
              continue
          computable = True
          for child in children[parent]:
              if not checked[child]:
                  computable = False
                  break
          if not computable:
              continue
          checked[parent] = True
          num_check += 1
          for child in children[parent]:
              n_path[parent] += n_path[child]
              for col_i in range(n):
                  c_path[parent][col_i] += (
                      n_path[child] if col[parent] == col_i else c_path[child][col_i]
                  )
          n_path[parent] += 1
          c_path[parent][col[parent]] += 1
  for col_i in range(n):
      ans = 0
      for p in range(n):
          if col[p] == col_i:
              ans += n_path[p]
              for c1 in children[p]:
                  for c2 in children[p]:
                      if c1 >= c2:
                          continue
                      ans += n_path[c1] * n_path[c2]
          else:
              ans += c_path[p][col_i]
              for c1 in children[p]:
                  for c2 in children[p]:
                      if c1 == c2:
                          continue
                      ans += c_path[c1][col_i] * (
                          n_path[c2] if c2 > c1 else n_path[c2] - c_path[c2][col_i]
                      )
      print(ans)
  
problem_description: Statement
  
  We have a tree with N vertices numbered 1 to N. The i-th edge in this tree
  connects Vertex a_i and b_i. Additionally, each vertex is painted in a color,
  and the color of Vertex i is c_i. Here, the color of each vertex is
  represented by an integer between 1 and N (inclusive). The same integer
  corresponds to the same color; different integers correspond to different
  colors.
  
  For each k=1, 2, ..., N, solve the following problem:
  
    * Find the number of simple paths that visit a vertex painted in the color k one or more times.
  
  **Note:** The simple paths from Vertex u to v and from v to u are not
  distinguished.
samples: [{"input": "3\n    1 2 1\n    1 2\n    2 3", "output": "5\n    4\n    0\n    \n\nLet P_{i,j} denote the simple path connecting Vertex i and j.\n\nThere are 5 simple paths that visit a vertex painted in the color 1 one or\nmore times:  \nP_{1,1}\\,,\\, P_{1,2}\\,,\\, P_{1,3}\\,,\\, P_{2,3}\\,,\\, P_{3,3}\n\nThere are 4 simple paths that visit a vertex painted in the color 2 one or\nmore times:  \nP_{1,2}\\,,\\, P_{1,3}\\,,\\, P_{2,2}\\,,\\, P_{2,3}\n\nThere are no simple paths that visit a vertex painted in the color 3 one or\nmore times.\n\n* * *"}, {"input": "1\n    1", "output": "1\n    \n\n* * *"}, {"input": "2\n    1 2\n    1 2", "output": "2\n    2\n    \n\n* * *"}, {"input": "5\n    1 2 3 4 5\n    1 2\n    2 3\n    3 4\n    3 5", "output": "5\n    8\n    10\n    5\n    5\n    \n\n* * *"}, {"input": "8\n    2 7 2 5 4 1 7 5\n    3 1\n    1 2\n    2 7\n    4 5\n    5 6\n    6 8\n    7 8", "output": "18\n    15\n    0\n    14\n    23\n    0\n    23\n    0"}]