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
  
  read = sys.stdin.buffer.read
  readline = sys.stdin.buffer.readline
  readlines = sys.stdin.buffer.readlines
  
  
  def solve(N, C, AB):
      def edges_to_array(A, B, N, M):
          head = [-1] * (N + 1)
          nxt = [0] * (M + M)
          to = [0] * (M + M)
          for i in range(M):
              a = A[i]
              b = B[i]
              nxt[i << 1] = head[a]
              to[i << 1] = b
              head[a] = i << 1
              nxt[i << 1 | 1] = head[b]
              to[i << 1 | 1] = a
              head[b] = i << 1 | 1
          return head, nxt, to
  
      def EulerTour(head, nxt, to, root=1):
          N = len(head) - 1
          parent = [0] * (N + 1)
          ind_L = [0] * (N + 1)
          ind_R = [0] * (N + 1)
          i = -1
          tour = []
          stack = [-root, root]
          stack[0] = -root
          stack[1] = root
          while stack:
              v = stack.pop()
              tour.append(v)
              i += 1
              if v > 0:
                  ind_L[v] = i
                  p = parent[v]
                  k = head[v]
                  while k != -1:
                      w = to[k]
                      if w == p:
                          k = nxt[k]
                          continue
                      parent[w] = v
                      stack.append(-w)
                      stack.append(w)
                      k = nxt[k]
              else:
                  ind_R[-v] = i
          return tour, ind_L, ind_R, parent
  
      head, nxt, to = edges_to_array(AB[::2], AB[1::2], N, N - 1)
      tour, ind_L, ind_R, parent = EulerTour(head, nxt, to)
      removed = [0] * (N + 1)
      answer = [N * (N + 1) // 2] * (N + 1)
      memo = [0] * (N + 1)
      for v in tour:
          if v > 0:
              memo[v] = removed[C[parent[v]]]
          else:
              v = -v
              removed[C[v]] += 1
              p = parent[v]
              x = (ind_R[v] - ind_L[v]) // 2 + 1  # subtree size
              x -= removed[C[p]] - memo[v]
              answer[C[p]] -= x * (x + 1) // 2
              removed[C[p]] += x
      for i, x in enumerate(removed):
          x = N - x
          answer[i] -= x * (x + 1) // 2
      return answer
  
  
  N = int(readline())
  C = (0,) + tuple(map(int, readline().split()))
  AB = tuple(map(int, read().split()))
  answer = solve(N, C, AB)
  print("\n".join(map(str, answer[1:])))
  
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"}]