3
we can solve this using dfs based approach4
identify the root of the tree and start a dfs from there7
def countSubTrees(self, n: int, edges: List[List[int]], labels: str) -> List[int]:8
graph_map = {i: set() for i in range(n)}10
graph_map[edge[0]].add(edge[1])11
graph_map[edge[1]].add(edge[0])13
result = [None for _ in range(n)]19
temp = [0 for _ in range(26)]20
temp[ord(labels[index]) - 97] += 121
for idx in graph_map[index]:22
if idx not in visited:24
temp = [a + b for a, b in zip(temp, x)]25
result[index] = temp[ord(labels[index]) - 97]