Free food | 프로그래밍의 벗 PivotOJ
PivotOJ

Free food

시간 제한: 1000ms메모리 제한: 1024MB출처: Programmeringsolympiaden 2016 — finalBOJ 21325
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

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 NN people numbered from 11 to NN. 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.

[이미지 1]

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

입력

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

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

The third line consists of MM 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.

힌트

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.

예제

예제 1

입력
5 3
5 5 4 1 0
1 2 3
출력
2

예제 2

입력
6 5
5 4 4 5 0 1
5 1 3 2 4
출력
1
코드를 제출하려면 로그인하세요.