12792 - Brute-forcibly Finding Tree Anagrams
|
Time |
Memory |
Case 1 |
1 sec |
32 MB |
Case 2 |
1 sec |
32 MB |
Case 3 |
1 sec |
32 MB |
Case 4 |
1 sec |
32 MB |
Case 5 |
1 sec |
32 MB |
Description
Anagrams means "變位字" in Chinese. Assume we have a word "HEART" and we want "HEART" to be the level-order sequence and "EARTH" to be the in-order sequence, the tree would exist. However, if we set "EARTH" to be the level-order sequence and "HEART" to be the in-order sequence, then the tree will not exist.



Input
1. Size in the following heap array
2. The given tree in the heap format
3. Number of the following word pairs
Output
Is each pair of words anagrams according to the given tree? Yes or No
Tags