#P5836. Milk Visits on the Farm Tree

    ID: 19064 Type: Default 1000ms 256MiB

Milk Visits on the Farm Tree

Milk Visits on the Farm Tree

Farmer John plans to build NN farms connected by N1N-1 roads forming a tree, so every farm can reach any other farm without any cycles. Each farm houses a cow which is either a Guernsey (denoted by 'G') or a Holstein (denoted by 'H').

Farmer John's MM friends visit him. For the ii-th friend, he travels along the unique path from farm AiA_i to farm BiB_i (note that AiA_i and BiB_i might be the same). During the visit, the friend can taste the milk of any cow along the path. Each friend has a strong preference and will only drink milk from a specific breed – some only drink Guernsey milk while others only drink Holstein milk. A friend is happy if and only if their preferred type of cow appears on the path they traverse.

inputFormat

The first line contains two integers NN and MM, representing the number of farms and the number of friends respectively.

The second line is a string of length NN consisting only of characters 'G' and 'H'. The ii-th character represents the type of cow at farm ii.

Each of the next N1N-1 lines contains two integers uu and vv, indicating that there is a road connecting farm uu and farm vv.

The following MM lines each contain two integers AiA_i, BiB_i and a character PiP_i (either 'G' or 'H'), representing the starting farm, ending farm, and the friend’s preferred cow type respectively.

outputFormat

Output a binary string of length MM. The ii-th character of the string should be '1' if the ii-th friend is happy (i.e. if the path from AiA_i to BiB_i contains at least one cow of type PiP_i) and '0' otherwise.

sample

4 3
GGGH
1 2
2 3
3 4
1 4 G
1 4 H
2 3 H
110

</p>