Logo
(追記) (追記ここまで)

27619번 - Two Charts Become One 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB54201938.000%

문제

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 K.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 K.1 are all truly different, each representing different hierarchies.

Figure K.1: Two sets of hierarchical charts.

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:

  1. a department number d by itself is a hierarchical chart
  2. the string \verb+d (c1) (c2) ... (cn)+ is a hierarchical chart, where d is a department number and c1, c2, ..., cn are hierarchical charts.

Case 2 represents the case where department d is in charge of the departments at the top of the hierarchies c1, c2, ..., cn. Each input line will contain at most 100ドル,000円$ departments and no department will be in charge of more than 100ドル$ other departments. All department numbers are integers between 1ドル$ and 1ドル,000円,000円$. We say that a hierarchical chart described by case 1 has leadership depth 1ドル,ドル and a hierarchical chart described by case 2 has leadership depth equal to one plus the maximum leadership depth of the hierarchical charts c1, c2, \dots, cn. The input will have a leadership depth at most 1ドル,000円$. There may be any number of spaces on either side of an opening or closing parenthesis.

출력

Output Yes if the two hierachical charts are similar and No otherwise.

제한

예제 입력 1

11 (10) (12 (13) (17) (28))
11 (12 (17) (28) (13)) (10)

예제 출력 1

Yes

예제 입력 2

11 ( 10 ) ( 12 )
11(10(12))

예제 출력 2

No

예제 입력 3

11 (10) (12)
11 (10) (13)

예제 출력 3

No

힌트

출처

ICPC > Regionals > North America > East Central North America Regional > 2022-2023 East Central Regional Contest K번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /