#GYM104614K. Two Charts Become One
Two Charts Become One
Description
When businesses feel that they are a little bloated and in need of restructuring, they call in the well-known reorganization consultant Don Sizing. One of the first things Don asks for is a chart showing the hierarchy of departments in the business, i.e., which departments are in charge of other departments. Often there will be some confusion about this hierarchy and Don will end up with two or more different charts displaying the same set of departments. In situations like this Don must determine if the charts are similar, i.e., if they show the exact set of hierarchies while not necessarily being drawn the same way. For example, consider the two charts shown on the left in Figure 1. While they do not look the same, they do represent the same hierarchies – department $11$ is in charge of departments $10$ and $12$ and department $12$ is in charge of departments $13$, $17$ and $28$. The three charts on the right in Figure 1 are all truly different, each representing different hierarchies.

For companies with small numbers of departments, determining whether two charts are the same is relatively simple, but for larger companies it can be rather difficult. Don has sized up this problem and decided he needs some software to solve this problem for him.
Input consists of two lines, each representing one hierarchical chart. The syntax for a hierarchical chart is the following:
- a department number d by itself is a hierarchical chart
- the string d (c1) (c2) ... (cn) is a hierarchical chart, where d is a department number and c1, c2, ..., cn are hierarchical charts.
Output Yes if the two hierachical charts are similar and No otherwise.
Input
Input consists of two lines, each representing one hierarchical chart. The syntax for a hierarchical chart is the following:
- a department number d by itself is a hierarchical chart
- the string d (c1) (c2) ... (cn) is a hierarchical chart, where d is a department number and c1, c2, ..., cn are hierarchical charts.
Output
Output Yes if the two hierachical charts are similar and No otherwise.
11 (10) (12 (13) (17) (28))
11 (12 (17) (28) (13)) (10)
11 ( 10 ) ( 12 )
11(10(12))
11 (10) (12)
11 (10) (13)
Yes
No
No