PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#LCA0000068. Yêu cầu về các chữ cái trên cây (Tree Requests)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

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 11, and every vertex has one lowercase English letter. The root has height 11, and child height is parent height plus 11. A query (v,h)(v,h) collects the letters from vertices in the subtree of vv with height exactly hh. 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: n qn\ q. Next are n−1n-1 parent indices p2,…,pnp_2,\ldots,p_n. Next line is a string ss of nn lowercase letters where sis_i belongs to vertex ii. Then qq queries v hv\ h.

Output

Print Yes if a palindrome is possible, otherwise No.

Subtasks

General constraints: 1≤n,q≤5⋅1051\le n,q\le 5\cdot10^5; 1≤pi<i1\le p_i<i; 1≤v≤n1\le v\le n; 1≤h≤n1\le h\le n; xâu chỉ chứa a–z.

  • Subtask 1 (20 points): 1≤n≤401\le n\le 40; 1≤q≤501\le q\le 50.

  • Subtask 2 (30 points): 1≤n≤10001\le n\le 1000; 1≤q≤10001\le q\le 1000.

  • Subtask 3 (50 points): 1≤n≤5000001\le n\le 500000; 1≤q≤5000001\le q\le 500000.

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 22 there are letters a and b, so no palindrome is possible. In subtree 22 at height 33 there are two b letters, which do form one. An empty set at height 55 also qualifies.