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: import sys
  
  input = sys.stdin.readline
  
  N = int(input())
  C = [0] + list(map(int, input().split()))
  E = [[] for i in range(N + 1)]
  
  for i in range(N - 1):
      a, b = map(int, input().split())
      E[a].append(b)
      E[b].append(a)
  
  from collections import deque
  
  QUE = deque([1])
  QUE2 = deque()
  EULER = [0]  # これが1からツアーで辿った点
  USED = [0] * (N + 1)
  Parent = [-1] * (N + 1)
  TOP_SORT = [1]
  Children = [[] for i in range(N + 1)]
  
  while QUE:
      x = QUE.pop()
      EULER.append(x)
  
      if USED[x] == 1:
          continue
  
      for to in E[x]:
  
          if USED[to] == 0:
              QUE2.append(to)
              Parent[to] = x
              Children[x].append(to)
              TOP_SORT.append(to)
          else:
              QUE.append(to)
      QUE.extend(QUE2)
      QUE2 = deque()
  
      USED[x] = 1
  
  CE = [[] for i in range(N + 1)]
  CTOP_SORT = [[] for i in range(N + 1)]
  
  for x in TOP_SORT:
      CTOP_SORT[C[x]].append(x)
  
  EFIRST = [-1] * (N + 1)
  ELAST = [-1] * (N + 1)
  for i in range(len(EULER)):
      if EFIRST[EULER[i]] == -1:
          EFIRST[EULER[i]] = i
      ELAST[EULER[i]] = i
  
      CE[C[EULER[i]]].append(i)
  
  Size = [1] * (N + 1)
  for i in TOP_SORT[1:][::-1]:
      Size[Parent[i]] += Size[i]
  
  Size[0] = N + 1
  
  
  LEN = len(EULER)
  
  BIT = [0] * (LEN + 1)  # 1-indexedなtree
  
  
  def update(v, w):  # index vにwを加える
      while v <= LEN:
          BIT[v] += w
          v += v & (-v)  # 自分を含む大きなノードへ. たとえばv=3→v=4
  
  
  def getvalue(v):  # [1,v]の区間の和を求める
      ANS = 0
      while v != 0:
          ANS += BIT[v]
          v -= v & (-v)  # 自分より小さい2ベキのノードへ. たとえばv=3→v=2へ
      return ANS
  
  
  for i in range(1, N + 1):
      update(EFIRST[i], 1)
  
  for color in range(1, N + 1):
      if CE[color] == []:
          print(0)
          continue
  
      EULER2 = CE[color]
      TOP_SORT2 = CTOP_SORT[color]
      HISTORY = []
  
      # print(EULER2,TOP_SORT2)
      # print(BIT)
  
      ANS = 0
      for x in TOP_SORT2[::-1]:
          for to in Children[x]:
              sc = getvalue(ELAST[to]) - getvalue(EFIRST[to] - 1)
              update(EFIRST[x], -sc)
              HISTORY.append((EFIRST[x], sc))
              ANS += sc * (sc + 1) // 2
          update(EFIRST[x], -1)
          HISTORY.append((EFIRST[x], 1))
  
      # print(ANS)
  
      sc = getvalue(len(EULER))
      ANS += sc * (sc + 1) // 2
  
      print(N * (N + 1) // 2 - ANS)
      for x, y in HISTORY:
          update(x, y)
  
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"}]