Company: Bolt.earth
Difficulty: medium
Black and White Tree Max score: 20.00 You are given a tree of N vertices numbered 1 through N, rooted at vertex 1. Being a tree, it is an undirected graph with exactly N - 1 edges, and edge i joins two vertices a i and b i . Every vertex i carries a colour, either white (shown as '0') or black (shown as '1'). Define the beauty of a vertex i as the count of paths inside its subtree whose two endpoints carry different colours. Report the beauty value for every one of the N vertices. Note: The subtree rooted at vertex i is the connected subgraph made up of i together with all of its descendants. Function Description Complete the function solve . This function takes the following 3 parameters: N : Represents the number of vertices Color : Represents the color of the vertices Edges : Represents the elements denoting the edge connecting two vertices Input Format The first line contains a single integer N denoting the number of vertices in the tree. The second line contains the string Color o