#B3748. Document Combination and Similarity Check

    ID: 11407 Type: Default 1000ms 256MiB

Document Combination and Similarity Check

Document Combination and Similarity Check

Fusu has not slept for 3636 hours while working on her theoretical computer science assignment. To speed up her sleep, she has found nn documents, where the ii-th document is a string sis_i. She plans to combine these documents using the following two operations:

1. 1 x y: Concatenate document sxs_x to the end of document sys_y, then delete sxs_x (it will never be used in later operations).

2. 2 x y: Query whether document sxs_x and document sys_y are similar.

Two documents are defined to be similar if one of them can be rearranged (i.e. its characters permuted) to become exactly equal to the other. In other words, they are anagrams of each other.

Note that the query operation does not modify any document.

inputFormat

The first line contains two positive integers nn and mm, representing the number of documents and the number of operations respectively. The next nn lines each contain a non-empty string sis_i. The following mm lines each describe an operation in one of the following two forms:

- 1 x y: Concatenate document sxs_x to the end of document sys_y, and then delete sxs_x.
- 2 x y: Output 'YES' if document sxs_x and sys_y are similar (anagrams), otherwise output 'NO'.

It is guaranteed that after a document is deleted via a type-1 operation, it will not appear in any later operation.

outputFormat

For each query operation (type 2), output a single line containing either 'YES' or 'NO', indicating whether the two specified documents are similar.

sample

3 3
ab
cd
abcd
1 1 2
2 2 3
2 3 2
YES

YES

</p>