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

문제

Tonight Hsara is going out for a dinner at a restaurant with his organisation and Hsara is thinking about the chances of someone else paying for the dinner. Exactly one person will pay for the entire dinner (everyone's food), but not any person. It is only allowed to pay for dinner if no supperior (possibly indirect, for example, your boss' boss) in the organisation is present at the table.

The organisation consists of $N$ people numbered from $1$ to $N$. Each person, except for the CEO, has exactly one boss. Given each person's boss and a list of people present at the table, determine how many people are able to pay for the dinner.

Figure 1: Illustration of the organisation in the first sample.

입력

The first line consists of two integers, $N$ - the number of people in the organisation and $1 \le M \le N$ - the number of people at the table.

The second line consists of $N$ integers. The $i$:th integer is the boss of person $i$. 0 means that person $i$ is the CEO. There will be exactly one CEO.

The third line consists of $M$ integers indicating the people present at the table.

출력

Print an integer - the number of people at the table who would be able to pay for the dinner.

제한

  • $2 \le N \le 100\,000$

예제 입력 1

5 3
5 5 4 1 0
1 2 3

예제 출력 1

2

예제 입력 2

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

예제 출력 2

1

힌트

In the first sample person 1 and person 2 can pay. Person 3 can't pay because person 1 is at the table.

In the second sample person 5 is the CEO and at the table. Therefore only person 5 can pay.

출처

Olympiad > Swedish Olympiad in Informatics > 2016 > Final B번

  • 문제를 만든 사람: Oskar Werkelin Ahlin