You are given an undirected tree with edges of length edges[i]
You are also given an integer array group of length group[i] denotes the group assigned to node i.
The interaction cost between a pair of distinct nodes u and v (group[u] == group[v]) is defined as the number of edges on the unique path between them.
Return the total sum of interaction costs across all pairs of distinct nodes that belong to the same group.
Constraints:
n
edges.length
edges[i]
group.length
group[i]
The input is generated such that edges represents a valid tree.
You are given an undirected tree with edges of length edges[i]
You are also given an integer array group of length group[i] denotes the group assigned to node i.
The interaction cost between a pair of distinct nodes u and v (group[u] == group[v]) is defined as the number of edges on the unique path between them.
Return the total sum of interaction costs across all pairs of distinct nodes that belong to the same group.
Constraints:
n
edges.length
edges[i]
group.length
group[i]
The input is generated such that edges represents a valid tree.