#LCA0000068. Yêu cầu về các chữ cái trên cây (Tree Requests)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Yêu cầu về các chữ cái trên cây (Tree Requests)
Tree Requests
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A tree is rooted at vertex , and every vertex has one lowercase English letter. The root has height , and child height is parent height plus . A query collects the letters from vertices in the subtree of with height exactly . Decide whether these letters can be rearranged to form a palindrome. Do not output the rearrangement. An empty set or a singleton always qualifies.
Input
First line: . Next are parent indices . Next line is a string of lowercase letters where belongs to vertex . Then queries .
Output
Print Yes if a palindrome is possible, otherwise No.
Subtasks
General constraints: ; ; ; ; xâu chỉ chứa a–z.
-
Subtask 1 (20 points): ; .
-
Subtask 2 (30 points): ; .
-
Subtask 3 (50 points): ; .
Examples
Input
5 4
1 1 2 2
aabbb
1 2
2 3
1 3
1 5
Output
No
Yes
Yes
Yes
Explanation
At height there are letters a and b, so no palindrome is possible. In subtree at height there are two b letters, which do form one. An empty set at height also qualifies.