| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 6 초 | 2048 MB | 92 | 30 | 23 | 31.507% |
Forrest Gump wants to participate in the annual Forest Run. As usual, the forest where this event takes place contains many trees. However, the forest for this year's run is special. The hiking trails are also shaped like trees; this means that each entrance into the forest branches off into multiple trails, these trails will never form a cycle, and entrances into the forest do not have incoming trails from another entrance. In order to finish the Forest Run, every path from every entrance to every trail end and back must be run.
All intersections in the forest (including the entrances) are numbered, starting from one. Every trail between two intersections is one kilometer long. You can neglect the distance between the entrances to the forest.
Can you calculate the full distance that Forrest must run in order to complete the Forest Run?
7 1 1 2 2 3 2 4 5 2 6 7 0 0 0 0
16
Figure F.1: The paths in the forest of the first sample input. Forrest will have to run the following path: $1-2-4-2-1-2-5-2-1-3-6-3-1-3-7-3-1$.
6 2 1 5 1 2 2 3 4 0 0 1 6 0
10
Figure F.2: The paths in the forest of the second sample input. Forrest will have to run the following paths: $1-2-3-2-1-2-4-2-1$ and $5-6-5$.