NC205924. FirstofHerName
描述
输入描述
The first line of input contains two integers n and k, where n (1 ≤ n ≤ 106 ) is the total number of RoyalLadies and k (1 ≤ k ≤ 106 ) is the number of query strings.Then follow n lines describing the Royal Ladies. The ith of these lines describes the Royal Lady numbered i, and contains an uppercase letter ci (‘A’–‘Z’) and an integer pi, where ciis the first letter of thename of Lady i, and pi (p1 = 0 and 1 ≤ pi < i for i > 1) is the number of her mother (or 0, in the caseof the First Lady). All the names are unique.The remaining k lines each contain one nonempty query string, consisting only of uppercase letters. Thesum of the lengths of the query strings is at most 106 .
输出描述
Output k lines, with the ith line containing the number of Royal Ladies who have the ith query string asa prefix of their name.
示例1
输入:
10 5 S 0 Y 1 R 2 E 3 N 4 E 5 A 6 D 7 Y 7 R 9 RY E N S AY
输出:
2 2 1 1 0