RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 R03735

Loza

설명

Scientists on Antarctica have found a new species! They extracted one sample and took it to the
laboratory for testing.
They quickly noticed the species reproduces quite often and that only one parent is required for
reproduction. However after the parent reproduces twice, it becomes sterile and cannot reproduce
again.
In spite of this the number of specimens in the laboratory skyrocketed and the need for family trees
appeared.
They decided to draw the tree in a simple text editor using following conventions:
The names of the specimens will be written inside nice boxes using characters '-', '|' and 'o'. The
center point of the upper and lower border will be marked by the character '+'. If the length of the
border is even, '+' will be on the left of the two center points.
o--+--o
|anton|
o--+--o
o----+----o
|anamarija|
o----+----o
o-+--o
|pero|
o-+--o
The boxes will be connected with links. One link connects two or more boxes on their respective '+'
characters, with the parent specimen placed above it's children. The boxes and links must not overlap.
+
|
o
|
+
+
|
o---o---o
| |
+ +
+
|
o-----o-----o
| |
+ +
If the parent has one child, a point to point (leftmost example) link is used. If the parent has two
children, a branching link is used, with the older child on the left, and the younger on the right.
Branching links may be expanded in the horizontal direction as long as the number of '-' characters on
both sides stays equal. Links cannot be expanded vertically.
Don't worry, you will not be asked to draw the tree, only determine the number of characters required
to draw it. Space characters are not counted, only '-', '|', '+' , 'o' and letters in the names.

제약

Test data worth 50 points has \(N < 30\).
Test data worth 75 points has \(N < 3000\).

입력 형식

The first line of input contains one integer N (\(1 \le N \le 300\,000\)), number of specimens in the
laboratory.
The specimens are marked with numbers 1 to N in the order of birth, with the oldest marked 1 and
youngest marked N.
The next N lines contain birth notes of all specimens in the order of birth. Each specimen (except the
first whose parent is unknown) is described with two pieces of information:
 na\(me - se\)quence of at most 20 lowercase english alphabet characters
 parent – one integer denoting the parent of this specimen

출력 형식

The first and only line of input should contain the minimal number of characters needed to draw the
family tree.

예제 1
입력
3
adam
kain 1
abel 1
출력
64
예제 2
입력
12
anton
ana 1
luka 1
mia 2
tea 3
jakov 3
semiramida 5
dominik 5
anamarija 4
eustahije 4
lovro 2
lovro 11
출력
371
Sample description:
   o-+--o
   |adam|
   o-+--o
     |
  o--o--o
  |     |
o-+--oo-+--o
|kain||abel|
o-+--oo-+--o
                             o--+--o
                             |anton|
                             o--+--o
                                |
                   o------------o------------o
                   |                         |
                 o-+-o                     o-+--o
                 |ana|                     |luka|
                 o-+-o                     o-+--o
                   |                         |
           o-------o-------o              o--o--o
           |               |              |     |
         o-+-o          o--+--o         o-+-oo--+--o
         |mia|          |lovro|         |tea||jakov|
         o-+-o          o--+--o         o-+-oo--+--o
           |               |              |
     o-----o-----o         o        o-----o-----o
     |           |         |        |           |
o----+----o o----+----o o--+--oo----+-----o o---+---o
|anamarija| |eustahije| |lovro||semiramida| |dominik|
o----+----o o----+----o o--+--oo----+-----o o---+---o
Counting the characters gives 64 and 371.
문제 정보

생성자가 기록되지 않았습니다.

출처 COI 2010

평가 및 의견

Loza

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Loza

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8