You are given a rooted tree with n vertices. The vertices are numbered from 1 to n, the root is the vertex number 1.

Each vertex has a color, let's denote the color of vertex v by c_{v}. Initially c_{v} = 0.

You have to color the tree into the given colors using the smallest possible number of steps. On each step you can choose a vertex v and a color x, and then color all vectices in the subtree of v (including v itself) in color x. In other words, for every vertex u, such that the path from root to u passes through v, set c_{u} = x.

It is guaranteed that you have to color each vertex in a color different from 0.

You can learn what a rooted tree is using the link: https://en.wikipedia.org/wiki/Tree_(graph_theory).


-----Input-----

The first line contains a single integer n (2 ≤ n ≤ 10^4) — the number of vertices in the tree.

The second line contains n - 1 integers p_2, p_3, ..., p_{n} (1 ≤ p_{i} < i), where p_{i} means that there is an edge between vertices i and p_{i}.

The third line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ n), where c_{i} is the color you should color the i-th vertex into.

It is guaranteed that the given graph is a tree. 


-----Output-----

Print a single integer — the minimum number of steps you have to perform to color the tree into given colors.


-----Examples-----
Input
6
1 2 2 1 5
2 1 1 1 1 1

Output
3

Input
7
1 1 2 3 1 4
3 3 1 1 1 2 3

Output
5



-----Note-----

The tree from the first sample is shown on the picture (numbers are vetices' indices):

$A$

On first step we color all vertices in the subtree of vertex 1 into color 2 (numbers are colors):

[Image]

On seond step we color all vertices in the subtree of vertex 5 into color 1:

[Image]

On third step we color all vertices in the subtree of vertex 2 into color 1:

[Image]

The tree from the second sample is shown on the picture (numbers are vetices' indices):

[Image]

On first step we color all vertices in the subtree of vertex 1 into color 3 (numbers are colors):

[Image]

On second step we color all vertices in the subtree of vertex 3 into color 1:

$8$

On third step we color all vertices in the subtree of vertex 6 into color 2:

[Image]

On fourth step we color all vertices in the subtree of vertex 4 into color 1:

[Image]

On fith step we color all vertices in the subtree of vertex 7 into color 3:

[Image]

Source: codeforces | Difficulty: EASY
Tags: Spanning trees

Graph traversal

Greedy algorithms


Solutions:
def read():
	return tuple((int(x) for x in input().split()))

def main():
	(n,) = read()
	edges = read()
	subs = []
	for i in range(n):
		subs.append([])
	for (i, x) in enumerate(edges):
		subs[x - 1].append(i + 1)
	colors_required = read()
	colors = [0] * n
	result = 0
	stack = [0]
	while len(stack) > 0:
		i = stack.pop()
		if colors[i] != colors_required[i]:
			result += 1
			colors[i] = colors_required[i]
		for j in subs[i]:
			colors[j] = colors[i]
			stack.append(j)
	return result
print(main())


from collections import defaultdict
n = int(input())
g = defaultdict(set)
lis = list(map(int, input().split()))
lis.insert(0, 0)
lis.insert(0, 0)
for i in range(2, n + 1):
	x = min(i, lis[i])
	y = max(i, lis[i])
	g[x].add(y)
clr = list(map(int, input().split()))
clr.insert(0, 0)
vis = [0] * (n + 1)
cc = [0] * (n + 1)
vis[1] = 1
cc[1] = clr[1]
c = 1
st = [1]
while st:
	x = st[-1]
	for i in g[x]:
		if vis[i] == 0:
			cc[i] = clr[x]
			vis[i] = 1
			if cc[i] != clr[i]:
				c += 1
				cc[i] = clr[i]
			st.append(i)
			break
	else:
		st.pop()
print(c)


n = int(int(input()))
parent = [0, 0] + list(map(int, input().split()))
color = [0] + list(map(int, input().split()))
cnt = 1
for i in range(2, n + 1, 1):
	if color[i] != color[parent[i]]:
		cnt += 1
print(cnt)


n = int(input())
P = [0] + list(map(lambda c: int(c) - 1, input().split()))
C = list(map(int, input().split()))
cnt = sum((C[i] == C[p] for (i, p) in enumerate(P)))
print(n - cnt + 1)


def o():
	return list(map(int, input().split()))
([n], [p, c]) = (o(), [o() for x in range(2)])
print(sum([1 if i == 0 or c[p[i - 1] - 1] != c[i] else 0 for i in range(n)]))


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def dfs(d, n, col):
	parentcol = [0] * (n + 1)
	count = 0
	parentcol[1] = col[0]
	visit = [False] * (n + 1)
	q = deque([1])
	while q:
		temp = q.pop()
		if col[temp] != parentcol[temp]:
			count += 1
			parentcol[temp] = col[temp]
		for x in d[temp]:
			if visit[x] == False:
				q.append(x)
				parentcol[x] = col[temp]
		visit[temp] = True
	print(count)

def main():
	try:
		d = defaultdict(list)
		n = I()
		l = list(In())
		for x in range(n - 1):
			d[x + 2].append(l[x])
			d[l[x]].append(x + 2)
		col = [0]
		col += list(In())
		dfs(d, n, col)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


n = int(input())
p = [0, 0]
c = [0]
p.extend(map(int, input().split()))
c.extend(map(int, input().split()))
answer = 1
for i in range(2, n + 1):
	if c[i] != c[p[i]]:
		answer += 1
print(answer)


read = lambda : list(map(int, input().split()))
n = input()
graphList = read()
colorList = read()

def minSteps():
	steps = 0
	for i in range(0, int(n) - 1):
		child = i + 1
		parent = graphList[i] - 1
		if colorList[child] != colorList[parent]:
			steps += 1
	return steps
print(minSteps() + 1)


n = int(input())
tree = list(map(int, input().split()))
colors = list(map(int, input().split()))
ans = 0
for i in range(1, n):
	if colors[i] != colors[tree[i - 1] - 1]:
		ans += 1
print(ans + 1)


from collections import *
import bisect
import heapq

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))

def bfs():
	visited = [False] * n
	visited[0] = True
	result = 1
	to_visit = deque()
	to_visit.append(0)
	while to_visit:
		node = to_visit.popleft()
		for child in graph[node]:
			if not visited[child]:
				if colors[child] != colors[node]:
					result += 1
				visited[child] = True
				to_visit.append(child)
	return result
n = ri()
edges = rl()
colors = rl()
graph = [[] for i in range(n)]
for i in range(n - 1):
	graph[i + 1].append(edges[i] - 1)
	graph[edges[i] - 1].append(i + 1)
ans = bfs()
print(ans)


n = int(input())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 1
for i in range(1, n):
	if c[i] != c[p[i - 1] - 1]:
		ans += 1
print(ans)


import sys
sys.setrecursionlimit(1000000)
read = sys.stdin.readline
n = int(read())
parent = [1] + list(map(int, read().split()))
color = list(map(int, read().split()))
underVertex = [[] for _ in range(n + 1)]
for (i, p) in enumerate(parent):
	if i + 1 != p:
		underVertex[p] += [i + 1]

def dfs(idx, c):
	count = 0
	if c != color[idx - 1]:
		count = 1
	for nxt in underVertex[idx]:
		count += dfs(nxt, color[idx - 1])
	return count
print(dfs(1, 0))


from collections import Counter
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def root(parent, a):
	while parent[a] != a:
		parent[a] = parent[parent[a]]
		a = parent[a]
	return a

def union(parent, size, a, b):
	(root_a, root_b) = (root(parent, a), root(parent, b))
	if root_a == root_b:
		return
	if size[root_a] >= size[root_b]:
		parent[root_b] = root_a
		size[root_a] += size[root_b]
		size[root_b] = 0
	else:
		parent[root_a] = root_b
		size[root_b] += size[root_a]
		size[root_a] = 0

def solve(adj, colors, n):
	ans = 1
	visited = [False] * n
	stack = [1]
	visited[1] = True
	while len(stack) > 0:
		node = stack.pop()
		for nd in adj[node]:
			if not visited[nd]:
				stack.append(nd)
				visited[nd] = True
				if colors[node] != colors[nd]:
					ans += 1
	return ans
n = iinput()
a = rlinput()
colors = rlinput()
colors.insert(0, 0)
adj = defaultdict(list)
for i in range(n - 1):
	adj[a[i]].append(i + 2)
print(solve(adj, colors, n + 1))


an = 0
import sys
sys.setrecursionlimit(2 * 100000)

def dfs(node, p):
	global an
	if p == -1 or co[node] != co[p]:
		an += 1
	for i in adj[node]:
		if i != p:
			dfs(i, node)
n = int(input())
p = [int(x) for x in input().split()]
co = [int(x) for x in input().split()]
dp = [1] * n
adj = [[] for i in range(n)]
for i in range(1, n):
	adj[i].append(p[i - 1] - 1)
	adj[p[i - 1] - 1].append(i)
dfs(0, -1)
print(an)


from queue import *
n = int(input())
parent = {}
child = {}
for i in range(1, n + 1):
	parent[i] = 0
	child[i] = []
l = list(map(int, input().split()))
for i in range(2, n + 1):
	parent[i] = l[i - 2]
	child[l[i - 2]].append(i)
l = list(map(int, input().split()))
color = {}
for i in range(1, n + 1):
	color[i] = l[i - 1]
q = Queue()
q.put(1)
ans = 0
while not q.empty():
	e = q.get()
	c = 0
	if e == 1:
		c = 0
	else:
		c = color[parent[e]]
	if c != color[e]:
		ans += 1
	for i in child[e]:
		q.put(i)
print(ans)


n = int(input())
s = input()
ss = input()
tree = [[1]]
p = list(map(int, s.split()))
q = list(map(int, ss.split()))
for i in range(0, n - 1):
	tree.append([i + 2])
	tree[p[i] - 1].append(i + 2)
count = 0
for each in tree:
	if len(each) == 1:
		tree.remove(each)
		count += 1
tree.sort(key=len)
for each in tree:
	sub = list(map(lambda x: q[x - 1], each[1:]))
	count += 1 - sub.count(q[each[0] - 1])
print(count)


from collections import defaultdict

class graph:

	def __init__(self, v):
		self.v = v
		self.graph = defaultdict(list)

	def add_edge(self, a, b):
		self.graph[a].append(b)

	def solve(self, c):
		pc = [0] * self.v
		visit = [0] * self.v
		s = [0]
		ans = 0
		while s:
			u = s.pop()
			if visit[u] == 0:
				visit[u] = 1
				if pc[u] != c[u]:
					ans += 1
			for j in self.graph[u]:
				if visit[j] == 0:
					pc[j] = c[u]
					s.append(j)
		print(ans)
n = int(input())
a = list(map(int, input().split()))
c = list(map(int, input().split()))
g = graph(n)
for i in range(n - 1):
	g.add_edge(a[i] - 1, i + 1)
g.solve(c)


Read = lambda : list(map(int, input().split()))
n = int(input())
p = [0, 0] + Read()
c = [0] + Read()
ans = 0
for i in range(2, n + 1):
	if c[i] != c[p[i]]:
		ans += 1
print(ans + 1)


n = int(input())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
graph = {i: set() for i in range(1, n + 1)}
for i in range(n - 1):
	graph[p[i]] = graph[p[i]].union(set([i + 1 + 1]))
steps = 1

def dfs_iterative(graph, node):
	global steps
	(stack, path) = ([node], [])
	while stack:
		vertex = stack.pop()
		if vertex in path:
			continue
		path.append(vertex)
		for neighbor in graph[vertex]:
			if c[vertex - 1] != c[neighbor - 1]:
				steps += 1
			stack.append(neighbor)
	return path
dfs_iterative(graph, 1)
print(steps)


from collections import defaultdict
t = int(input())
g = defaultdict(list)
l = list(map(int, input().split()))
c = list(map(int, input().split()))
for i in range(t - 1):
	(a, b) = (i + 2, l[i])
	a = a - 1
	b = b - 1
	g[b].append(a)
copyc = [0] * t
ans = 0
visited = [0] * t
stack = [0]
while stack:
	p = stack.pop()
	if visited[p] == 0:
		visited[p] = 1
		if copyc[p] != c[p]:
			ans += 1
	for i in range(len(g[p])):
		if visited[g[p][i]] == 0:
			stack.append(g[p][i])
			copyc[g[p][i]] = c[p]
print(ans)


import sys

def main1():
	n = int(input())
	paths = [int(x) for x in input().split(' ')]
	colors = [int(x) for x in input().split(' ')]
	dict = {}
	for j in range(n - 1):
		i = j + 1
		key = paths[j] - 1
		if key in dict:
			dict[key].append(i)
		else:
			l = list()
			l.append(i)
			dict[key] = l
	vertexColors = [0] * n

	def dfs(root):
		count = 0
		if root in dict:
			for child in dict[root]:
				vertexColors[child] = colors[root]
				if colors[child] != colors[root]:
					count += 1
					count += dfs(child)
				else:
					count += dfs(child)
		return count
	try:
		count1 = dfs(0) + 1
		print(count1)
	except Exception as e:
		print('type error: ' + str(e))
sys.setrecursionlimit(200000)
main1()


import sys

def dfs(node, color):
	ans = 0
	if color != c[node]:
		color = c[node]
		ans += 1
	for i in child[node]:
		ans += dfs(i, color)
	return ans
sys.setrecursionlimit(10002)
n = int(input())
parent = [0] + list(map(int, input().split()))
c = list(map(int, input().split()))
child = [[] for i in range(n)]
for i in range(1, n):
	child[parent[i] - 1].append(i)
print(dfs(0, 0))


import sys
sys.setrecursionlimit(10 ** 6)
N = int(input())
G = [[] for i in range(N)]
p = list(map(int, input().split()))
C = list(map(int, input().split()))
num = 0
for i in range(1, N):
	G[p[i - 1] - 1].append(i)

def dfs(u, par, c):
	global num
	if C[u] != c:
		num += 1
	for w in G[u]:
		if w == par:
			continue
		dfs(w, u, C[u])
dfs(0, -1, -1)
print(num)


import sys
I = lambda : map(int, sys.stdin.readline().split())
n = int(input())
par = [0 for i in range(n + 1)]
col = [0 for i in range(n + 1)]
li = list(I())
l1 = list(I())
ans = 1
for i in range(2, n + 1):
	par[i] = li[i - 2]
for i in range(1, n + 1):
	col[i] = l1[i - 1]
ans = 1
for i in range(2, n + 1):
	if col[i] != col[par[i]]:
		ans += 1
print(ans)


a = [int(i) for i in range(1, int(input()) + 1)]
edges = [int(i) for i in input().split()]
color = [int(i) for i in input().split()]
answer = 1
for (i, j) in zip(color[1:], edges):
	if color[j - 1] != i:
		answer += 1
print(answer)


n = int(input())
edge = []
for i in range(n + 10):
	edge.append([])
vert = [int(i) for i in input().split()]
target_colors = [int(i) for i in input().split()]
target_colors = [0] + target_colors
for i in range(2, n + 1):
	edge[i].append(vert[i - 2])
	edge[vert[i - 2]].append(i)
colors = [0] * (n + 1)
colors[1] = target_colors[0]
used = [0] * (n + 1)
stack = [1]
head = -1
tail = 0
ans = 1
used[1] = 1
while head < len(stack) - 1:
	head += 1
	v = stack[head]
	for w in edge[v]:
		if used[w]:
			continue
		used[w] = 1
		if target_colors[v] != target_colors[w]:
			ans += 1
		stack.append(w)
print(ans)


from io import BytesIO
import os
from collections import defaultdict, deque
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline

def dfs(graph, color):
	count = 1
	stack = deque()
	visited = [False] * (len(graph) + 1)
	stack.append(1)
	while stack:
		top = stack.pop()
		visited[top] = True
		for neighbor in graph[top]:
			if not visited[neighbor]:
				if color[neighbor] != color[top]:
					count += 1
				stack.append(neighbor)
	return count

def main():
	int(input())
	paths = list(map(int, input().split()))
	colors = [0]
	colors.extend(list(map(int, input().split())))
	graph = defaultdict(list)
	for (index, edge) in enumerate(paths):
		node = index + 2
		graph[node].append(edge)
		graph[edge].append(node)
	print(dfs(graph, colors))
main()


ii = lambda : int(input())
kk = lambda : map(int, input().split())
ll = lambda : list(kk())
n = ii()
parents = [-1] * n
edges = {i: [] for i in range(n)}
ls = kk()
for i in range(1, n):
	o = ls.__next__() - 1
	edges[i].append(o)
	edges[o].append(i)
parents[0] = 0
rcol = ll()
lowest = [0]
cnt = 1
while lowest:
	l2 = []
	for l in lowest:
		if rcol[parents[l]] != rcol[l]:
			cnt += 1
		for child in edges[l]:
			if child == parents[l]:
				continue
			parents[child] = l
			l2.append(child)
	lowest = l2
print(cnt)


n = int(input())
mps = list(map(int, input().split()))
col = list(map(int, input().split()))
st = 2
par = dict()
for i in range(n - 1):
	par[st] = par.get(st, [])
	par[st].append(mps[i])
	par[mps[i]] = par.get(mps[i], [])
	par[mps[i]].append(st)
	st += 1
queue = [1]
vis = [0] * (n + 1)
ans = 1
while len(queue):
	s = queue.pop(0)
	vis[s] = 1
	for i in par[s]:
		if not vis[i]:
			queue.append(i)
			vis[i] = 1
			if col[i - 1] != col[s - 1]:
				ans += 1
print(ans)


import sys
sys.setrecursionlimit(5000)
n = int(input())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 1
for (i, x) in enumerate(p):
	if c[i + 1] != c[x - 1]:
		ans += 1
print(ans)


n = int(input())
T = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
T_inv = [[] for _ in range(n)]
for i in range(n - 1):
	T_inv[T[i] - 1] += [i + 1]
result = 1
for i in range(n):
	for child in T_inv[i]:
		if C[i] != C[child]:
			result += 1
print(result)


input()
links = [int(i) for i in input().split(' ')]
colors = [int(i) for i in input().split(' ')]
i = 1
count = 1
while i < len(links) + 1:
	if colors[links[i - 1] - 1] != colors[i]:
		count += 1
	i += 1
print(count)


n = int(input())
pl = list(map(int, input().split()))
cl = list(map(int, input().split()))
pl = [0] + [p - 1 for p in pl]
sl = [None] * n
for i in range(n):
	if sl[i] is not None:
		continue
	j = i
	while pl[j] != j and cl[pl[j]] == cl[j]:
		sl[j] = False
		j = pl[j]
	sl[j] = True
print(sum(sl))


import queue

def my_solve(n, graph, mask, colors):
	steps = 1
	q = queue.Queue()
	q.put(1)
	mask[1] = 1
	while not q.empty():
		u = q.get()
		for v in graph[u]:
			if mask[v] == 0:
				if colors[v - 1] != colors[u - 1]:
					steps += 1
				mask[v] = 1
				q.put(v)
		mask[u] = 2
	return steps

def test(n, edges, colors):
	graph = {}
	mask = [0] * (n + 5)
	for i in range(1, n + 1):
		graph[i] = []
	for i in range(0, len(edges)):
		graph[edges[i]].append(i + 2)
	return my_solve(n, graph, mask, colors)
n = int(input())
line1 = [int(x) for x in input().split()]
line2 = [int(x) for x in input().split()]
print(test(n, line1, line2))


n = int(input().strip())
p = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
moves = 1
for i in range(1, n):
	if c[p[i - 1] - 1] != c[i]:
		moves += 1
print(moves)


from collections import deque
n = int(input())
l = list(map(int, input().split()))
k = list(map(int, input().split()))
col_dict = {i + 1: k[i] for i in range(n)}
d = {i: [] for i in range(1, n + 1)}
c = 2
for i in l:
	d[i].append(c)
	c += 1
col = [0 for i in range(n + 1)]
q = deque()
q.append(1)
ans = 0
while q:
	a = q.popleft()
	if col[a] == col_dict[a]:
		for i in d[a]:
			q.append(i)
		continue
	color = col_dict[a]
	col[a] = color
	stack = [a]
	while stack:
		z = stack.pop()
		for i in d[z]:
			col[i] = color
			stack.append(i)
	for i in d[a]:
		q.append(i)
	ans += 1
print(ans)


def bfs(endcolor):
	color = [0] * (n + 1)
	endcolor = [0] + endcolor
	count = 0
	(visited, queue) = (set(), [1])
	while queue:
		vertex = queue.pop(0)
		if endcolor[vertex] != color[vertex]:
			color[vertex] = endcolor[vertex]
			count += 1
		if vertex not in visited:
			visited.add(vertex)
			queue.extend(g[vertex] - visited)
			for x in g[vertex] - visited:
				color[x] = color[vertex]
	return count
n = int(input())
g = {x: set() for x in range(1, n + 2)}
i = 1
for x in map(int, input().split()):
	i += 1
	g[x].add(i)
print(bfs(list(map(int, input().split()))))


from sys import stdin
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
n = I()
tr = list(R())
clr = list(R())
stp = 1
for i in range(2, n + 1):
	if clr[i - 1] != clr[tr[i - 2] - 1]:
		stp += 1
print(stp)


import sys
sys.setrecursionlimit(5000)
v = int(input())
A = []
for i in range(v):
	A += [[[], 0]]
ed = list(map(int, input().split()))
for (i, q) in enumerate(ed):
	A[q - 1][0] += [i + 1]
target = list(map(int, input().split()))
an = 0

def paint(node, lC):
	re = 0
	if lC != target[node]:
		re += 1
	for a in A[node][0]:
		re += paint(a, target[node])
	return re
an = paint(0, 0)
print(an)


n = int(input())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
count = 0
for i in range(n - 1):
	if c[i + 1] == c[p[i] - 1]:
		continue
	else:
		count += 1
print(count + 1)


I = lambda : map(int, input().split())
(n,) = I()
(a, b, s, q) = ([1] + [*I()], [*I()], 0, {})
for i in range(1, n + 1):
	q[i] = 0
for i in range(n):
	if q[a[i]] != b[i]:
		s += 1
	q[i + 1] = b[i]
print(s)


n = int(input())
a = [0, 0] + list(map(int, input().split()))
c = [0] + list(map(int, input().split()))
ans = 1
for i in range(2, n + 1):
	if c[i] != c[a[i]]:
		ans += 1
print(ans)


def solve():
	n = get(int)
	children = defaultdict(list)
	P = get([int])
	for (i, p) in enumerate(P, 2):
		children[i].append(p)
		children[p].append(i)
	col = dict(zip(range(1, n + 1), get([int])))
	stack = [(1, None, 0)]
	count = 0
	while stack:
		(node, parent, pcolor) = stack.pop()
		if pcolor != col[node]:
			count += 1
		pcolor = col[node]
		for c in children[node]:
			if c != parent:
				stack.append((c, node, pcolor))
	return count
_testcases = '\n6\n1 2 2 1 5\n2 1 1 1 1 1\n\n3\n\n\n\n7\n1 1 2 3 1 4\n3 3 1 1 1 2 3\n\n5\n'.strip()
from bisect import bisect_left, bisect_right
from collections import defaultdict
from functools import lru_cache
from heapq import heapify, heappop, heappush
from operator import itemgetter, attrgetter
import bisect
import collections
import functools
import heapq
import itertools
import math
import operator
import re
import string
import sys
inf = float('inf')
cache = lru_cache(None)
sys.setrecursionlimit(10000)

def tree():
	return collections.defaultdict(tree)

def equal(x, y, epsilon=1e-06):
	if -epsilon <= x - y <= epsilon:
		return True
	if -epsilon <= x <= epsilon or -epsilon <= y <= epsilon:
		return False
	return -epsilon <= (x - y) / x <= epsilon or -epsilon <= (x - y) / y <= epsilon

def get(_type):
	if type(_type) == list:
		if len(_type) == 1:
			_type = _type[0]
			return list(map(_type, input().strip().split()))
		else:
			return [_type[i](inp) for (i, inp) in enumerate(input().strip().split())]
	else:
		return _type(input().strip())
printRecursionTree = timeit = lambda x: x
(_p, print) = (print, lambda *a, **b: None)
_p(solve())


n = int(input())
nodes = list(map(int, input().split()))
color = list(map(int, input().split()))
from collections import defaultdict

def DFS(d, x, visited, color):
	c = 0
	visited[x] = 1
	z = 0
	stack = [x]
	temp = x
	while len(stack):
		temp = stack.pop()
		visited[temp] = 1
		for j in d[temp]:
			if visited[j] == 0 and color[temp - 1] != color[j - 1]:
				c = c + 1
				stack.append(j)
			elif visited[j] == 0 and color[temp - 1] == color[j - 1]:
				stack.append(j)
	return c
d = defaultdict(list)
for i in range(n - 1):
	d[nodes[i]].append(i + 2)
t = 1
visited = [0 for i in range(n + 1)]
c = 1
print(DFS(d, t, visited, color) + 1)


n = int(input())
children = [[] for _ in range(n)]
ps = [int(v) for v in input().split()]
for (i, p) in enumerate(ps, 1):
	children[p - 1].append(i)
cs = [int(v) for v in input().split()]
ans = 0
stack = [(0, 0)]
while stack:
	(v, c) = stack.pop()
	if c != cs[v]:
		ans += 1
		c = cs[v]
	for child in children[v]:
		stack.append((child, c))
print(ans)


import sys, math, cmath, time, collections
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import nsmallest, nlargest, heapify, heappop, heappush, heapreplace
from math import ceil, floor, log, log2, sqrt, gcd, factorial, pow, pi
from bisect import bisect_left, bisect_right
start_time = time.time()

def solve(g, colors, n):
	q = deque()
	found = set()
	q.append((0, 0))
	parent = [-1] * n
	order = []
	while q:
		(node, p) = q.popleft()
		if node in found:
			continue
		found.add(node)
		parent[node] = p
		order.append(node)
		for nei in g[node]:
			q.append((nei, node))
	color = [-1] * n
	count = 0
	for node in order:
		if colors[node] == color[parent[node]]:
			pass
		else:
			count += 1
		color[node] = colors[node]
	print(count)

def main():
	n = int(input())
	edges = list(map(int, input().split()))
	edges = [c - 1 for c in edges]
	color = list(map(int, input().split()))
	color = [c - 1 for c in color]
	g = defaultdict(list)
	for (i, c) in enumerate(edges, 1):
		g[i].append(c)
		g[c].append(i)
	solve(g, color, n)
LOCAL = False
if LOCAL:
	sys.stdin = open('../io/data.in', 'r')
	sys.stdout = open('../io/data.out', 'w')
testcases = 1
for i in range(testcases):
	main()
if LOCAL:
	print(f'Time Elapsed: {time.time() - start_time} seconds')
	sys.stdout.close()


n = int(input())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
col = 1
for i in range(2, n + 1):
	if c[i - 1] != c[p[i - 2] - 1]:
		col += 1
print(col)


from collections import defaultdict, deque
graph = defaultdict(list)
n = int(input())
p = list(map(int, input().split()))
for i in range(0, n - 1):
	graph[p[i]].append(i + 2)
c = list(map(int, input().split()))
answer = 1
q = deque([1])
while q:
	node = q.popleft()
	for child in graph[node]:
		if c[child - 1] != c[node - 1]:
			answer += 1
		q.append(child)
print(answer)


n = int(input())
l = [0]
s = 0
l.extend([int(i) - 1 for i in input().split()])
m = [int(i) for i in input().split()]
cv = [0] * n
if m[0] != 0:
	cv[0] = m[0]
	s += 1
for i in range(n):
	if m[i] != cv[l[i]]:
		cv[i] = m[i]
		s += 1
	else:
		cv[i] = cv[l[i]]
print(s)


import sys
inp = sys.stdin.readline
input = lambda : inp().strip()
flush = sys.stdout.flush

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))

def BFS(s, adj, color):
	ans = 1
	parent = {s: None}
	cl = {s: color[0]}
	u = [s]
	while u:
		nextu = []
		for i in u:
			for v in adj[i]:
				if v not in parent:
					if color[v] != cl[i]:
						cl[v] = color[v]
						ans += 1
					else:
						cl[v] = cl[i]
					parent[v] = i
					nextu.append(v)
		u = nextu.copy()
	return ans

def main():
	n = iin()
	adj = [[] for i in range(n)]
	a = lin()
	for i in range(1, n):
		adj[i].append(a[i - 1] - 1)
		adj[a[i - 1] - 1].append(i)
	color = lin()
	print(BFS(0, adj, color))
main()


from collections import deque
n = int(input())
graph = {i: [] for i in range(1, n + 1)}
Ans = 0
edge = list(map(int, input().split()))
for i in range(n - 1):
	(a, b) = (i + 2, edge[i])
	graph[a].append(b)
	graph[b].append(a)
colorlist = list(map(int, input().split()))
colorlist = [0] + colorlist

def search(N):
	global Ans
	startnode = N
	visitedlist = [0 for i in range(n + 1)]
	d = deque()
	e = deque()
	d.append(N)
	visitedlist[N] = True
	while d:
		for point in d:
			for node in graph[point]:
				if visitedlist[node] == False:
					e.append(node)
					visitedlist[node] = True
					if colorlist[node] != colorlist[point]:
						Ans += 1
				elif visitedlist[node] == True:
					pass
		if e:
			d = e
			e = deque()
		elif not e:
			d = deque()
search(1)
print(Ans + 1)


from sys import stdout, stdin, setrecursionlimit
from io import BytesIO, IOBase
from collections import *
from itertools import *
from bisect import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

def getInt():
	return int(input())

def listStr():
	return list(input())

def getStrs():
	return input().split()

def isInt(s):
	return '0' <= s[0] <= '9'

def input():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in input().split()]

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n = getInt()
p = [0] + zzz()
c = [0] + zzz()
result = 1
for i in range(1, n):
	v1 = i + 1
	v2 = p[i]
	if c[v1] != c[v2]:
		result += 1
print(result)


n = int(input())
e = [int(i) - 1 for i in input().split()]
v = [int(i) for i in input().split()]
counter = 1
for i in range(n - 1):
	if v[e[i]] != v[i + 1]:
		counter += 1
print(counter)


def compute():
	n = int(input())
	s = [int(i) for i in input().split(' ')]
	desirable = [int(i) for i in input().split(' ')]
	color = [0 for i in range(n)]
	G = [0 for i in range(n)]
	for i in range(len(s)):
		G[i + 1] = s[i] - 1
	counter = 1
	color[0] = desirable[0]
	for i in range(1, n):
		if desirable[i] != color[G[i]]:
			color[i] = desirable[i]
			counter += 1
		else:
			color[i] = desirable[i]
	print(counter)
compute()


from collections import defaultdict
n = int(input())
a = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
d = defaultdict(list)
for i in range(2, n + 1):
	t = a[i - 2]
	p = min(i, t)
	q = max(i, t)
	d[p].append(q)
count = 0
for i in d:
	p = c[i - 1]
	for j in range(len(d[i])):
		q = d[i][j]
		if c[q - 1] != p:
			count += 1
print(count + 1)


from collections import defaultdict

def bfs(src):
	q = []
	v[src] = 1
	q.append(src)
	while q:
		s = q.pop(0)
		for i in d[s]:
			if v[i] == 0:
				v[i] = 1
				q.append(i)
				d1[i] = s
n = int(input())
d = defaultdict(list)
l = list(map(int, input().split()))
c = list(map(int, input().split()))
j = 2
for i in range(n - 1):
	d[l[i]].append(j)
	j += 1
st = 1
l = [c[0]] * n
v = {}
for i in range(1, n + 1):
	v[i] = 0
d1 = {}
bfs(1)
st = 1
l = [c[0]] * n
for i in range(1, n):
	node = i + 1
	parent = d1[node]
	if c[node - 1] != c[parent - 1]:
		st += 1
print(st)


n = int(input())
graph = [[] for i in range(n)]
l = list(map(int, input().split(' ')))
for i in range(n - 1):
	graph[i + 1] += [l[i] - 1]
	graph[l[i] - 1] += [i + 1]
cc = list(map(int, input().split(' ')))
ll = range(n)
colors = [0 for i in range(n)]
counter = 0
visited = [False for i in range(n)]
ans = 0
counter = 0
q = [i]
visited[i] = True
while len(q) != 0:
	u = q[0]
	q.pop(0)
	for j in graph[u]:
		if visited[j]:
			continue
		if cc[j] != cc[u]:
			counter += 1
		visited[j] = True
		q += [j]
print(counter + 1)


n = int(input())
graph = [[] for i in range(n)]
for (index, i) in enumerate(input().split()):
	graph[int(i) - 1].append(index + 1)
colors = [int(i) for i in input().split()]
stack = [0]
ans = 0
while stack:
	if graph[stack[-1]]:
		c = graph[stack[-1]].pop()
		if colors[stack[-1]] != colors[c]:
			ans += 1
		stack.append(c)
	else:
		stack.pop()
print(ans + 1)


import sys

def read():
	return [int(v) for v in input().split()]

def count(v, parent, tree, colors):
	cnt = 0
	if parent == -1:
		cnt += 1
	if parent != -1 and colors[v] != colors[parent]:
		cnt += 1
	for vnext in tree[v]:
		if vnext != parent:
			cnt += count(vnext, v, tree, colors)
	return cnt

def main():
	n = read()[0]
	tree = [[] for i in range(n)]
	p = read()
	for (i, v) in enumerate(p, 1):
		tree[i].append(v - 1)
		tree[v - 1].append(i)
	colors = read()
	sys.setrecursionlimit(10 ** 5)
	print(count(0, -1, tree, colors))
main()


def pst(root, curr):
	global times
	if cs[root - 1] != curr:
		times += 1
	curr = cs[root - 1]
	if root not in vss:
		return
	chn = vss[root]
	for ch in chn:
		pst(ch, curr)
n = int(input())
vs = [int(x) for x in input().split()]
cs = [int(x) for x in input().split()]
vss = {}
for (c, p) in enumerate(vs):
	if not p in vss:
		vss[p] = [c + 2]
	else:
		vss[p].append(c + 2)
times = 0

def flattened():
	times = 0
	root = 1
	curr = 0
	firstpart = True
	stack = []
	while True:
		if firstpart:
			if cs[root - 1] != curr:
				times += 1
			curr = cs[root - 1]
			if root not in vss:
				firstpart = False
				if len(stack) == 0:
					print(times)
					return
				(chni, curr) = stack.pop()
			else:
				chn = vss[root]
				chni = iter(chn)
		try:
			ch = next(chni)
			firstpart = True
			root = ch
			stack.append((chni, curr))
		except StopIteration:
			firstpart = False
			if len(stack) == 0:
				print(times)
				return
			(chni, curr) = stack.pop()
flattened()


n = int(input())
pohon = [0, 0] + list(map(int, input().split()))
warna = [0] + list(map(int, input().split()))
step = 1
for node in range(2, n + 1, 1):
	if warna[node] != warna[pohon[node]]:
		step += 1
print(step)


import queue
n = int(input().strip())
g = [[] for _ in range(n)]
p = list(map(int, input().strip().split(' ')))
for _ in range(len(p)):
	fa = p[_] - 1
	g[fa].append(_ + 1)
	g[_ + 1].append(fa)
c = list(map(int, input().strip().split(' ')))
bfs = queue.Queue()
bfs.put((-1, 0, -1))
ans = 0
while not bfs.empty():
	cur = bfs.get()
	col = cur[2]
	if col != c[cur[1]]:
		ans += 1
		col = c[cur[1]]
	for rt in g[cur[1]]:
		if rt == cur[0]:
			continue
		bfs.put((cur[1], rt, col))
print(ans)


class Node:

	def __init__(self, name):
		self.name = name
		self.cv = 0
		self.adjacencyList = []

class Edge:

	def __init__(self, startnode, endnode):
		self.startnode = startnode
		self.endnode = endnode
n = int(input())
nodes = []
for i in range(1, n + 1):
	nodes.append(Node(i))
start = 2
edges = list(map(int, input().split()))
edgelist = []
for edge in edges:
	edgelist.append(Edge(nodes[edge - 1], nodes[start - 1]))
	start += 1
colors = list(map(int, input().split()))
counter = 0
for (i, color) in enumerate(colors):
	nodes[i].cv = color
for e in edgelist:
	if e.startnode.cv != e.endnode.cv:
		counter += 1
print(counter + 1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import threading
sys.setrecursionlimit(10 ** 4)
threading.stack_size(10 ** 8)

def dfs(x):
	global v, adj, c, ans
	v[x] = 1
	for i in adj[x]:
		if not v[i]:
			if c[i - 1] != c[x - 1]:
				ans += 1
			dfs(i)

def main():
	global v, adj, c, ans
	n = int(input())
	l = list(map(int, input().split()))
	c = list(map(int, input().split()))
	v = [0] * (n + 1)
	adj = [[] for i in range(n + 1)]
	ans = 1
	for i in range(n - 1):
		if i + 2 != l[i]:
			adj[i + 2].append(l[i])
			adj[l[i]].append(i + 2)
	dfs(1)
	print(ans)
t = threading.Thread(target=main)
t.start()
t.join()


import sys
sys.setrecursionlimit(1000000)

class Edge:

	def init(self, u, v, next):
		self.u = u
		self.v = v
		self.next = next
MAXN = int(100000.0 + 10)
vis = [0] * MAXN
edge = [None] * MAXN * 2
head = [-1] * MAXN
cnt = [0]
color = [0] * MAXN
ans = [1]

def addedge(u, v):
	edge[cnt[0]] = Edge()
	edge[cnt[0]].init(u, v, head[u])
	head[u] = cnt[0]
	cnt[0] += 1

def dfs(u):
	if vis[u] == 1:
		return
	vis[u] = 1
	i = head[u]
	while i != -1:
		e = edge[i]
		v = e.v
		if vis[v] == 0:
			if color[u] != colorneed[v]:
				ans[0] += 1
			color[v] = colorneed[v]
			dfs(v)
		i = e.next
n = int(input())
p = list(map(int, input().split()))
for i in range(n - 1):
	addedge(i + 1, p[i] - 1)
	addedge(p[i] - 1, i + 1)
colorneed = list(map(int, input().split()))
color[0] = colorneed[0]
dfs(0)
print(ans[0])


n = int(input())
p = [int(a) for a in input().split()]
c = [int(a) for a in input().split()]
N = 1
for i in range(n - 1):
	if c[i + 1] != c[p[i] - 1]:
		N += 1
print(N)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 1
for i in range(n - 1):
	if b[i + 1] != b[a[i] - 1]:
		ans += 1
print(ans)


class Node(object):

	def __init__(self, n, color):
		self.n = n
		self.color = color

def main():
	nv = int(input())
	l = input()
	l = l.split(' ')
	l = [int(i) for i in l]
	g = [[] for i in range(0, nv + 1)]
	c = 2
	for v in l:
		g[v].append(c)
		c += 1
	colors = input()
	colors = colors.split(' ')
	colors = [0] + colors
	steps = 0
	queue = [Node(1, '0')]
	while len(queue) != 0:
		curr_node = queue.pop(0)
		if curr_node.color != colors[curr_node.n]:
			steps += 1
		for n in g[curr_node.n]:
			queue.append(Node(n, colors[curr_node.n]))
	print(steps)
main()


n = int(input())
p = [0] + [int(i) for i in input().split()]
c = [0] + [int(i) for i in input().split()]
result = 1
for i in range(1, n):
	v1 = i + 1
	v2 = p[i]
	if c[v1] != c[v2]:
		result += 1
print(result)


n = int(input())
p = [0] + list(map(int, input().split()))
c = [0] + list(map(int, input().split()))
res = 1
mp = {i: [] for i in range(1, n + 1)}
for i in range(1, len(p)):
	mp[p[i]].append(i + 1)
col = {i: 0 for i in range(1, n + 1)}
q = [1]
while q != []:
	cur = q.pop(0)
	for i in mp[cur]:
		q.append(i)
	if cur == 1:
		col[cur] = c[cur]
	else:
		col[cur] = col[p[cur - 1]]
		if col[cur] != c[cur]:
			col[cur] = c[cur]
			res += 1
print(res)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
graph = [[] for _ in range(n + 1)]
for i in range(2, n + 1):
	(u, v) = (i, a[i - 2])
	graph[u].append(v)
	graph[v].append(u)
queue = [1]
visited = [False] * (1 + n)
visited[1] = True
ans = 1
while queue:
	s = queue.pop()
	for child in graph[s]:
		if not visited[child]:
			if b[child - 1] != b[s - 1]:
				ans += 1
			visited[child] = True
			queue.append(child)
print(ans)


n = int(input())
m = []
p = list(map(int, input().split()))
c = [0] + list(map(int, input().split()))
m = [1] + [list() for i in range(n)]
for i in range(n - 1):
	m[p[i]].append(i + 2)
stack = [[1, c[1]]]
k = 1
while stack:
	(x, col) = stack.pop(0)
	for i in m[x]:
		if c[i] != col:
			k += 1
		stack.append([i, c[i]])
print(k)


(n, p, c) = (int(input()), list(map(int, input().split())), list(map(int, input().split())))
print(1 + sum((c[i + 1] != c[pi - 1] for (i, pi) in enumerate(p))))


from collections import deque
n = int(input())
p = list(map(int, input().split()))
arr = []
c = deque([])
c.extend(list(map(int, input().split())))
c.extendleft([0])
arr = deque([])
arr.extend([list() for i in range(n)])
arr.appendleft([1])
for i in range(2, n + 1):
	arr[p[i - 2]].append(i)
stack = [[1, c[1]]]
ans = 1
while stack != []:
	(x, color) = stack.pop(0)
	for elem in arr[x]:
		if c[elem] != color:
			ans += 1
		stack.append([elem, c[elem]])
print(ans)


n = int(input())
p = list(map(int, input().split()))
g = [[] for _ in range(n)]
for i in range(n - 1):
	g[i + 1].append(p[i] - 1)
	g[p[i] - 1].append(i + 1)
c = list(map(int, input().split()))
v = [-1] * n
v[0] = 0
s = [0]
o = 1
while s:
	x = s.pop()
	if c[x] != c[v[x]]:
		o += 1
	for j in g[x]:
		if v[j] == -1:
			s.append(j)
			v[j] = x
print(o)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
import heapq
n = int(input())
arr = list(map(int, input().split()))
ls = list(map(int, input().split()))
ans = 1
for i in range(n - 1):
	if ls[arr[i] - 1] != ls[i + 1]:
		ans += 1
print(ans)


def solve(num, edge, color):
	times = 1
	currentColor = [color[0]] * num
	index = 1
	while index < num:
		vertexAbove = edge[index - 1]
		currentColor[index] = currentColor[vertexAbove - 1]
		if currentColor[index] != color[index]:
			times += 1
			currentColor[index] = color[index]
		index += 1
	return times
n = int(input())
edge = list(map(int, input().split()))
color = list(map(int, input().split()))
print(solve(n, edge, color))


import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
dict = {}
for i in range(n):
	dict[i] = []
l1 = list(map(int, input().split()))
for i in range(0, n - 1):
	dict[i + 1].append(l1[i] - 1)
	dict[l1[i] - 1].append(i + 1)
l2 = list(map(int, input().split()))

def bfs(start, n, visited, l2, color):
	count = 0
	color[start] = l2[start]
	q = [start]
	q = deque(q)
	count += 1
	visited[start] = 1
	while len(q) != 0:
		y = dict[q[0]]
		for j in y:
			if visited[j] == 0:
				if color[q[0]] != l2[j]:
					count += 1
					color[j] = l2[j]
				else:
					color[j] = l2[j]
				visited[j] = 1
				q.append(j)
		q.popleft()
	print(count)
visited = [0] * n
color = [0] * n
bfs(0, n, visited, l2, color)


def main():
	n = int(input())
	parents = [int(x) - 1 for x in input().strip().split()]
	colors = [int(x) for x in input().strip().split()]
	ans = 1
	for i in range(n - 1):
		c = i + 1
		p = parents[i]
		if colors[c] != colors[p]:
			ans += 1
	print(ans)
main()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
tree = []
for i in range(1, n + 1):
	tree.append([i])
for j in range(2, n + 1):
	tree[a[j - 2] - 1].append(j)
s = 0
for each in tree:
	if len(each) == 1:
		s += 1
		tree.remove(each)
for subset in tree:
	subset = list(map(lambda x: b[x - 1], subset))
	colour = subset[0]
	s = s - subset.count(colour) + 2
print(s)


n = int(input())
pi = list(map(int, input().split()))
ci = list(map(int, input().split()))
com = 1
for i in range(1, n):
	if ci[i] != ci[pi[i - 1] - 1]:
		com += 1
print(com)


n = int(input())
d = {1: []}
c = 1
for i in input().split():
	c += 1
	d[c] = []
	d[int(i)] += [c]
z = list(map(int, input().split()))
c = list(range(1, n + 1))
pr = list((1 for i in range(n)))
o = 0
while c:
	for j in d[c[0]]:
		if z[j - 1] == z[c[0] - 1]:
			pr[j - 1] = 0
	o += pr[c[0] - 1]
	c.pop(0)
print(o)


n = int(input())
arestas = list(map(int, input().split()))
cores = list(map(int, input().split()))
arestas.insert(0, 0)
arestas.insert(0, 0)
cores.insert(0, 0)
count = 1
for i in range(2, n + 1):
	if cores[i] != cores[arestas[i]]:
		count += 1
print(count)


from collections import defaultdict
n = int(input())
graph = defaultdict(lambda : defaultdict(int))
edges = []
for (i, v) in enumerate(input().split()):
	i = int(i)
	v = int(v)
	graph[v][i + 2] = 1
	edges.append((i + 2, v))
colors = {}
for (i, v) in enumerate(input().split()):
	colors[int(i) + 1] = int(v)
ans = 0
for (u, v) in edges:
	if colors[u] != colors[v]:
		ans += 1
print(ans + 1)


from collections import deque
n = int(input())
adj = [[] for i in range(n + 1)]
for (i, x) in enumerate(input().split()):
	i += 2
	x = int(x)
	adj[i].append(x)
	adj[x].append(i)
parents = [0 for i in range(n + 1)]
parents[1] = -1
colors = [-1] + [int(x) for x in input().split()]
q = deque([1])
while len(q) > 0:
	node = q.popleft()
	for x in adj[node]:
		if parents[x] == 0:
			parents[x] = node
			q.append(x)
ans = 1
for i in range(2, n + 1):
	if colors[i] != colors[parents[i]]:
		ans += 1
print(ans)


N = int(input())
peaks = list(map(int, input().split()))
target = list(map(int, input().split()))
i = 1
for (p, c) in zip(peaks, target[1:]):
	if c != target[p - 1]:
		i += 1
print(i)


import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase
import string

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None
		self.BUFSIZE = 8192

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split(' ')))

def get_int_grid(n):
	return [get_ints() for _ in range(n)]

def get_str():
	return input().split(' ')

def yes_no(b):
	if b:
		return 'YES'
	else:
		return 'NO'

def binary_search(good, left, right, delta=1, right_true=False):
	limits = [left, right]
	while limits[1] - limits[0] > delta:
		if delta == 1:
			mid = sum(limits) // 2
		else:
			mid = sum(limits) / 2
		if good(mid):
			limits[int(right_true)] = mid
		else:
			limits[int(~right_true)] = mid
	if good(limits[int(right_true)]):
		return limits[int(right_true)]
	else:
		return False

def prefix_sums(a, drop_zero=False):
	p = [0]
	for x in a:
		p.append(p[-1] + x)
	if drop_zero:
		return p[1:]
	else:
		return p

def prefix_mins(a, drop_zero=False):
	p = [float('inf')]
	for x in a:
		p.append(min(p[-1], x))
	if drop_zero:
		return p[1:]
	else:
		return p

def solve_a():
	n = get_int()
	p = get_ints()
	c = get_ints()
	colors = 1
	for (i, x) in enumerate(p):
		if c[x - 1] != c[i + 1]:
			colors += 1
	return colors
print(solve_a())


import sys
sys.setrecursionlimit(100000)
n = int(input())
par = list(map(int, input().split()))
kids = [[] for _ in range(n + 1)]
for i in range(n - 1):
	kids[par[i] - 1].append(i + 1)
c = list(map(int, input().split()))

def dfs(i, color):
	global par
	global kid
	global c
	ans = 0
	if c[i] != color:
		ans = 1
	for kid in kids[i]:
		ans += dfs(kid, c[i])
	return ans
print(dfs(0, 0))


n = int(input())
p = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
connects = {a: [] for a in range(1, n + 1)}
count = 1
for i in range(n - 1):
	connects[p[i]].append(i + 2)
for i in connects:
	for j in connects[i]:
		if c[i - 1] != c[j - 1]:
			count += 1
print(count)


n = int(input())
pai = input().split()
pai = [None] + [int(x) - 1 for x in pai]
corFinal = input().split()
corAtual = []
for cor in corFinal:
	corAtual.append(0)
corAtual[0] = corFinal[0]
pintei = 1
i = 1
while corAtual != corFinal:
	if corAtual[pai[i]] != corFinal[i]:
		pintei += 1
	corAtual[i] = corFinal[i]
	i += 1
print(pintei)


import sys
lines = []
for line in sys.stdin:
	lines.append(line.rstrip('\r\n\t '))
n = int(lines[0])
data = lines[1].split(' ')
tree = [0]
for x in data:
	tree.append(int(x))
data = lines[2].split(' ')
colors = [int(data[0])]
operations = 1
for i in range(n):
	if i > 0:
		color = int(data[i])
		parent = tree[i]
		if colors[parent - 1] != color:
			operations += 1
		colors.append(color)
print(operations)


N = int(input())
con = [0]
vert = [i for i in range(1, N + 1)]
a = input().split(' ')
for i in range(N - 1):
	con.append(int(a[i]) - 1)
color = []
a = input().split(' ')
for i in range(N):
	color.append(int(a[i]))
cur = [color[0] for i in range(N)]
steps = 1
for i in range(1, N):
	if cur[con[i]] == color[i]:
		cur[i] = color[i]
	else:
		steps += 1
		cur[i] = color[i]
print(steps)


n = int(input())
es = list(map(int, input().split()))
g = [[] for i in range(n)]
for (i, e) in enumerate(es):
	g[i + 1].append(e - 1)
	g[e - 1].append(i + 1)
cols = list(map(int, input().split()))
ans = 0
q = [[0, 0]]
vis = set([0])
while len(q) > 0:
	(v, c) = (q[0][0], q[0][1])
	del q[0]
	nc = cols[v]
	if nc != c:
		ans += 1
	for u in g[v]:
		if u not in vis:
			vis.add(u)
			q.append([u, nc])
print(ans)


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())
n = mint()
p = list(mints())
c = list(mints())
r = 0
for i in range(len(p)):
	if c[i + 1] != c[p[i] - 1]:
		r += 1
print(r + 1)


from collections import defaultdict
r = lambda : list(map(int, input().split()))
import sys
sys.setrecursionlimit(10 ** 5)
n = int(input())
arr = defaultdict(list)
x = r()
for i in range(2, n + 1):
	arr[x[i - 2]].append(i)
color = r()
paint = [-1] * (n + 1)
need = 0

def go(i, curr):
	global need
	if curr != color[i - 1]:
		need += 1
		paint[i] = color[i - 1]
		curr = paint[i]
	for node in arr[i]:
		go(node, curr)
go(1, -1)
print(need)


n = int(input())
(c, p) = ([0] * (n + 1), [0] * (n + 1))
p[2:n + 1] = list(map(int, input().split()))
c[1:n + 1] = list(map(int, input().split()))
ret = 1
for i in range(2, n + 1):
	if c[p[i]] != c[i]:
		ret += 1
print(ret)


from collections import deque
n = int(input())
adj = {i: [] for i in range(n)}
for (ind, val) in enumerate(input().split()):
	adj[int(val) - 1].append(ind + 1)
colors = [x for x in input().split()]
q = deque()
q.append([0, 0])
cnt = 0
while len(q):
	(node, color) = q.popleft()
	if colors[node] != color:
		cnt += 1
	for x in adj[node]:
		q.append([x, colors[node]])
print(cnt)


from queue import Queue
N = int(input())
children = {}
parent = {}
for i in range(1, N + 1):
	children[i] = []
	parent[i] = 0
ls = list(map(int, input().split()))
for i in range(2, N + 1):
	parent[i] = ls[i - 2]
	children[ls[i - 2]].append(i)
ls = list(map(int, input().split()))
color = {}
for i in range(1, N + 1):
	color[i] = ls[i - 1]
Q = Queue()
Q.put(1)
cnt = 0
while not Q.empty():
	element = Q.get()
	if element == 1:
		compare = 0
	else:
		compare = color[parent[element]]
	if color[element] != compare:
		cnt += 1
	for i in children[element]:
		Q.put(i)
print(cnt)


n = int(input())
lst = []
for x in input().split():
	lst.append(int(x))
array = []
for x in input().split():
	array.append(int(x))
mass = [array[0]] * n
k = 1
for x in range(1, len(mass)):
	mass[x] = mass[lst[x - 1] - 1]
	if mass[x] != array[x]:
		mass[x] = array[x]
		k += 1
print(k)


from collections import defaultdict as di
from collections import deque as dq
n = int(input())
coupl = di(list)
nodess = [int(x) - 1 for x in input().split()]
for i in range(n - 1):
	node = nodess[i]
	coupl[i + 1].append(node)
	coupl[node].append(i + 1)
colors = [int(x) - 1 for x in input().split()]
Q = dq()
found = set()
Q.append((0, 0))
parent = [-1] * n
order = []
while Q:
	(node, p) = Q.popleft()
	if node in found:
		continue
	found.add(node)
	parent[node] = p
	order.append(node)
	for nei in coupl[node]:
		Q.append((nei, node))
color = [-1] * n
count = 0
for node in order:
	if colors[node] == color[parent[node]]:
		pass
	else:
		count += 1
	color[node] = colors[node]
print(count)


import sys
f = sys.stdin
n = f.readline()
n = int(n)
ch = [[] for _ in range(n)]
p = f.readline().split()
for (i, x) in enumerate(p):
	ch[int(x) - 1].append(i + 1)
c = f.readline().split()
c = [int(x) for x in c]
tt = [0 for _ in range(n + 2)]
q = [0]
bot = 0
while bot < len(q):
	i = q[bot]
	bot += 1
	for child in ch[i]:
		q.append(child)
while len(q) > 0:
	i = q.pop(-1)
	cnt_sum = 0
	for child in ch[i]:
		cnt = tt[child]
		cnt_sum += cnt
		if c[child] == c[i]:
			cnt_sum -= 1
	tt[i] = cnt_sum + 1
print(tt[0])


nodes = int(input())
parents = [None, None]
parents += [int(p) for p in input().split()]
final = [int(p) for p in input().split()]
graph = []
for i in range(nodes + 1):
	graph.append([])
for i in range(len(parents)):
	if parents[i] is not None:
		graph[parents[i]].append(i)
initial = [0] * (len(final) + 1)
steps = 0
for i in range(1, len(initial)):
	p = parents[i]
	if p is None:
		initial[i] = final[i - 1]
		steps += 1
	elif initial[p] != final[i - 1]:
		initial[i] = final[i - 1]
		steps += 1
	else:
		initial[i] = final[i - 1]
		continue
print(steps)


from collections import *
import sys
import math
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def li():
	return [int(i) for i in input().rstrip('\n').split(' ')]

def st():
	return input().rstrip('\n')

def val():
	return int(input())

def stli():
	return [int(i) for i in input().rstrip('\n')]

def bfs(c, di):
	tot = 1
	d = deque()
	for i in di[1]:
		d.append([i, c[0]])
	visited = [0 for i in range(len(c) + 1)]
	while d:
		(root, itcolor) = d.popleft()
		if itcolor != c[root - 1]:
			tot += 1
			itcolor = c[root - 1]
		visited[root] = 1
		for i in di[root]:
			if not visited[i]:
				d.append([i, itcolor])
	return tot
n = val()
d = defaultdict(list)
l = li()
for i in range(n - 1):
	d[l[i]].append(i + 2)
c = li()
print(bfs(c, d))


from collections import defaultdict

def main():
	n = int(input())
	d = defaultdict(list)
	for (i, e) in enumerate(map(int, input().split()), 2):
		d[e].append(i)
	c = {i: int(c) for (i, c) in enumerate(input().split(), 1)}
	ans = 1
	for (k, v) in d.items():
		for e in v:
			if c[e] != c[k]:
				ans += 1
	print(ans)
main()


import sys

def eulertour(node, color):
	ans = 0
	if color != col[node]:
		color = col[node]
		ans += 1
	for i in child[node]:
		ans += eulertour(i, color)
	return ans
sys.setrecursionlimit(10002)
n = int(input())
par = [0] + [int(x) for x in input().split()]
col = [int(x) for x in input().split()]
child = [[] for i in range(n)]
for i in range(1, n):
	child[par[i] - 1].append(i)
print(eulertour(0, 0))


def main():
	n = int(input())
	g = [[] for _ in range(n)]
	for (u, v) in enumerate(map(int, input().split()), 1):
		g[u].append(v - 1)
		g[v - 1].append(u)
	cc = list(map(int, input().split()))
	(avail, st) = ([True] * n, [0])
	avail[0] = False
	while st:
		u = st.pop()
		c = cc[u]
		for v in g[u]:
			if avail[v]:
				avail[v] = False
				st.append(v)
				if cc[v] == c:
					n -= 1
	print(n)
main()


n = int(input())
p = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
ans = 1
ind = 1
for i in p:
	if c[i - 1] != c[ind]:
		ans += 1
	ind += 1
print(ans)


from collections import deque
from collections import defaultdict

def addEdge(a, b):
	graph[a].append(b)
	graph[b].append(a)

def Bfs(src):
	q = deque([])
	q.append(src)
	visited[src] = True
	ans = 0
	while q:
		node = q.popleft()
		if node == 1:
			ans += 1
		elif parent[node] == color[node - 1]:
			pass
		else:
			ans += 1
		for neighbour in graph[node]:
			if not visited[neighbour]:
				q.append(neighbour)
				visited[neighbour] = True
				parent[neighbour] = color[node - 1]
	return ans
n = int(input())
graph = [[] for i in range(n + 1)]
arr = list(map(int, input().split()))
color = list(map(int, input().split()))
visited = [False] * (n + 1)
parent = [-1] * (n + 1)
for i in range(n - 1):
	addEdge(i + 2, arr[i])
ans = Bfs(1)
print(ans)


from collections import deque

def solve():
	n = int(input())
	graph = dict()
	for i in range(1, n + 1):
		graph[i] = list()
	p = list(map(int, input().split()))
	index = 2
	for i in range(n - 1):
		graph[index].append(p[i])
		graph[p[i]].append(index)
		index += 1
	colors = [0]
	for c in map(int, input().split()):
		colors.append(c)
	checked = [False for _ in range(n + 1)]
	step = 1
	q = deque()
	q.append(1)
	while q:
		root = q.popleft()
		temp_color = colors[root]
		checked[root] = True
		for neighbor in graph[root]:
			if not checked[neighbor]:
				checked[neighbor] = True
				q.append(neighbor)
				if temp_color != colors[neighbor]:
					step += 1
	print(step)
solve()


n = int(input())
parent = [0] + list(map(int, input().split()))
colour = list(map(int, input().split()))
current = [0 for i in range(n)]
count = 0
for i in range(n):
	if colour[i] != current[i]:
		current[i] = colour[i]
		count += 1
		for j in range(i + 1, n):
			current[j] = current[parent[j] - 1]
print(count)


n = int(input())
parent = list(map(int, input().split()))
c = list(map(int, input().split()))
cnt = 1
for i in range(1, n):
	if c[i] != c[parent[i - 1] - 1]:
		cnt += 1
print(cnt)


import sys
sys.setrecursionlimit(100000000)
(mod, MOD) = (1000000007, 998244353)
from collections import deque, Counter, OrderedDict, defaultdict

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
count = 0

def dfs(root, curr):
	global count
	if root == 1:
		count += 1
		curr = color[root]
		visited[root] = True
	for child in mydict[root]:
		if not visited[child]:
			if color[child] != color[root]:
				count += 1
			visited[child] = True
			dfs(child, color[child])
n = int(input())
mydict = defaultdict(list)
Arr = get_array()
parent = dict()
myset = set()
for i in range(n - 1):
	mydict[Arr[i]].append(i + 2)
	parent[i + 2] = Arr[i]
visited = [False] * (n + 1)
color = [0] + get_array()
for i in color[1:]:
	myset.add(i)
if len(myset) == n:
	print(n)
	exit()
root = 1
curr = 0
dfs(root, curr)
print(count)


n = int(input())
edge = list(map(int, input().split(' ')))
color = list(map(int, input().split(' ')))
asscolor = [0 for i in range(n)]
visi = []
cadj = []
adjli = []
for i in range(n):
	adjli.append([])
	cadj.append(0)
	visi.append(0)
for i in range(len(edge)):
	adjli[i + 1].append(edge[i] - 1)
	adjli[edge[i] - 1].append(i + 1)

def dfs():
	global adjli, cadj, color, asscolor
	ans = 0
	stack = [0]
	asscolor[0] = color[0]
	ans += 1
	while len(stack) > 0:
		curr = stack[-1]
		visi[curr] = 1
		if asscolor[curr] != color[curr]:
			asscolor[curr] = color[curr]
			ans += 1
		if cadj[curr] < len(adjli[curr]):
			if visi[adjli[curr][cadj[curr]]] == 0:
				stack.append(adjli[curr][cadj[curr]])
				asscolor[adjli[curr][cadj[curr]]] = asscolor[curr]
			elif visi[adjli[curr][cadj[curr]]] == 1:
				cadj[curr] += 1
		else:
			del stack[-1]
	print(ans)
dfs()


n = int(input())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 1
for (i, x) in enumerate(p):
	if c[i + 1] != c[x - 1]:
		ans += 1
print(ans)


import sys
sys.setrecursionlimit(10000000)

def dfsColor(prarent, arr):
	global count
	for node in arr:
		if colors[node] != colors[prarent]:
			count += 1
		if len(graph[node]) > 0:
			dfsColor(node, graph[node])
n = int(input())
p = list(map(int, input().split()))
graph = [[] for _ in range(n + 1)]
for i in range(n - 1):
	need = p[i]
	im = i + 2
	graph[need].append(im)
colors = list(map(int, input().split()))
colors.insert(0, 0)
count = 1
visited = [1]
dfsColor(1, graph[1])
print(count)


def f():
	q = [1]
	cnt = 0
	while q:
		x = q.pop(0)
		for i in tree[x]:
			if color[x] != color[i]:
				cnt += 1
			q.append(i)
	return cnt
n = int(input())
tree = {i + 1: [] for i in range(n)}
color = {i + 1: 0 for i in range(n)}
p = list(map(int, input().split()))
for i in range(2, n + 1):
	tree[p[i - 2]].append(i)
c = list(map(int, input().split()))
for i in range(1, n + 1):
	color[i] = c[i - 1]
print(f() + 1)


import sys
sys.setrecursionlimit(10 ** 9)
from collections import defaultdict

def dfs(nd):
	vis[nd] = 1
	for i in graph[nd]:
		if vis[i] == 0:
			if col[i - 1] == col[nd - 1]:
				dfs(i)
			else:
				q.append(i)
for _ in range(1):
	n = int(input())
	graph = defaultdict(list)
	l = list(map(int, input().split()))
	col = list(map(int, input().split()))
	for i in range(2, n + 1):
		graph[i].append(l[i - 2])
		graph[l[i - 2]].append(i)
	vis = [0] * (n + 1)
	q = [1]
	tc = 0
	while q:
		tc += 1
		dfs(q.pop(0))
	print(tc)


def main():
	N = int(input())
	parent = [-1, -1]
	parent.extend(list(map(int, input().split())))
	color = [-1]
	color.extend(list(map(int, input().split())))
	cnt = 0
	for i in range(2, len(color)):
		if color[parent[i]] != color[i]:
			cnt += 1
	print(cnt + 1)
main()