시간 제한메모리 제한제출정답맞힌 사람정답 비율
6 초 2048 MB92302331.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?

입력

  • One line with two integers: $1 \leq n \leq 10^6$, the number of intersections in the forest, and $1 \leq e \leq n$, the number of entrances into the forest.
  • One line with $e$ integers: these are the numbers of the intersections that are the entrances to the forest.
  • $n$ lines, one for each intersection $i$. Each line has one integer $0 \leq c_i \leq n - 1$, indicating the number of trails exiting intersection $i$, followed by $c_i$ integers which are the numbers of the intersections that the trails exiting intersection $i$ lead to.

출력

  • One line containing one integer, which is the amount of kilometers that Forrest must run.

예제 입력 1

7 1
1
2 2 3
2 4 5
2 6 7
0
0
0
0

예제 출력 1

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$.

예제 입력 2

6 2
1 5
1 2
2 3 4
0
0
1 6
0

예제 출력 2

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$.