Company: Bolt.earth
Difficulty: medium
Black and White Tree Max score: 20.00 Given a tree with N vertices labeled from 1 to N, rooted at vertex 1. The tree is an undirected graph with N - 1 edges. Each edge i connects two vertices, a i and b i . Each vertex i is colored either white (represented by \'0\') or black (represented by \'1\'). The beauty of a vertex i is the number of paths in its subtree that have end vertices of the opposite color. Find the beauty of all N vertices. Note: A subtree of a vertex i is a connected sub-graph consisting of all the descendants of i including i. 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 of size N consisting of characters \'0\' and \'1\