Processing math: 100%
White path - MarisaOJ: Marisa Online Judge

White path

Time limit: 1000 ms
Memory limit: 256 MB
Consider a tree with n vertices, where each vertex is assigned either a white or black color. We want to determine the count of vertices, denoted as u, on the simple path from vertex 1 to vertex u, where the number of white vertices exceeds the number of black vertices. ### Input - The first line contains an integers n. - The second line contains a binary string of length n, denoting the color of n vertices. The ith character is the color of vertex i. 1 is black and 0 is white. - The next n−1 lines, each line contains two integers u,v, there is an edge between u and v. ### Output - Print the satisfied vertices. ### Constraints - 1≤n≤105. - 1≤u,v≤n. ### Example Input: 40110122324 Output: 2