Logo
(追記) (追記ここまで)

23712번 - Juke Artem 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 512 MB1144100.000%

문제

You are given a tree with $n$ vertices enumerated from 0ドル$ to $n - 1$ inclusive. There is a number in each vertex. Numbers are from 0ドル$ to $n - 1$ and are all distinct (i.e. they form a permutation). The number $x$ is in its place if it is in the $x$-th vertex.

You are allowed to swap two numbers at the endpoints of some edge of the tree. This costs you 0 if at least one of those numbers was in its place before the swap and 1 otherwise.

What is the minimum cost you have to pay to put all numbers in their places?

입력

The first line contains a single integer $n$ (2ドル \leq n \leq 10^5$), the number of vertices of the tree.

The second line contains $n - 1$ integers $p_i$ (0ドル \leq p_i < i$). $i$-th of them describes an edge between vertices $p_i$ and $i$.

The third line contains $n$ integers $a_i$ (0ドル \leq a_i < n$). $i$-th of them (in zero based indexing) is equal to the number which is initially in the $i$-th vertex. $a$ is a permutation.

출력

Print a single integer --- the minimum cost you have to pay.

제한

예제 입력 1

2
0
0 1

예제 출력 1

0

예제 입력 2

2
0
1 0

예제 출력 2

1

예제 입력 3

3
0 0
0 2 1

예제 출력 3

2

힌트

출처

Contest > Open Cup > 2018/2019 Season > Stage 16: Grand Prix of Moscow J번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /