| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 3 초 | 2048 MB | 73 | 45 | 36 | 72.000% |
While you are attending the yearly family gathering of your family, you notice that your family keeps growing bigger and bigger. You are having a hard time remembering for every member of the family what their name is and to what part of the family they belong to. To solve this, you decide to create a family tree on a big sheet of paper. You collect a portrait picture from every member of the family and stick them onto the paper in the shape of a tree, putting pictures of children exactly one level below the picture of their parents.
Before actually sticking the pictures on the paper, you need to figure out how much paper you need. Environmentally aware as you are, you try to minimize the amount of paper needed. You decide to allow pictures within the same level to move to the left or right if this makes the tree less wide (see also the examples below).
A - B", indicating that A is the parent of B. These lines have no particular order.The name of each person consists of at most 20 characters from the English alphabet (A-Z and a-z).
The minimum width of the family tree in the number of portrait pictures.
8 Alice Alice - Bob Alice - Carol Alice - Dave Bob - Eve Bob - Frank Carol - Grace Carol - Heidi
4
Figure F.1: The family tree belonging to the first example, with a maximum width of 4 on the bottom row.
8 Alice Alice - Bob Alice - Carol Alice - Dave Alice - Eve Bob - Frank Bob - Grace Carol - Heidi
4
Figure F.2: The family tree belonging to the second example, with a maximum width of 4 on the middle row.