{"raw_statement":[{"iden":"statement","content":"You are given a rooted tree with _n_ vertices. The vertices are numbered from 1 to _n_, the root is the vertex number 1.\n\nEach vertex has a color, let's denote the color of vertex _v_ by _c__v_. Initially _c__v_ = 0.\n\nYou 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_.\n\nIt is guaranteed that you have to color each vertex in a color different from 0.\n\nYou can learn what a rooted tree is using the link: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory))."},{"iden":"input","content":"The first line contains a single integer _n_ (2 ≤ _n_ ≤ 104) — the number of vertices in the tree.\n\nThe 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_.\n\nThe 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.\n\nIt is guaranteed that the given graph is a tree."},{"iden":"output","content":"Print a single integer — the minimum number of steps you have to perform to color the tree into given colors."},{"iden":"examples","content":"Input\n\n6\n1 2 2 1 5\n2 1 1 1 1 1\n\nOutput\n\n3\n\nInput\n\n7\n1 1 2 3 1 4\n3 3 1 1 1 2 3\n\nOutput\n\n5"},{"iden":"note","content":"The tree from the first sample is shown on the picture (numbers are vetices' indices):\n\n![image](https://espresso.codeforces.com/f543b5881f8f90906c7fb8c0dae62f2443b92ea1.png)\n\nOn first step we color all vertices in the subtree of vertex 1 into color 2 (numbers are colors):\n\n![image](https://espresso.codeforces.com/1c7bb267e2c1a006132248a43121400189309e2f.png)\n\nOn seond step we color all vertices in the subtree of vertex 5 into color 1:\n\n![image](https://espresso.codeforces.com/2201a6d49b89ba850ff0d0bdcbb3f8e9dd3871a8.png)\n\nOn third step we color all vertices in the subtree of vertex 2 into color 1:\n\n![image](https://espresso.codeforces.com/6fa977fcdebdde94c47695151e0427b33d0102c5.png)\n\nThe tree from the second sample is shown on the picture (numbers are vetices' indices):\n\n![image](https://espresso.codeforces.com/d70f9ae72a2ed429dd6531cac757e375dd3c953d.png)\n\nOn first step we color all vertices in the subtree of vertex 1 into color 3 (numbers are colors):\n\n![image](https://espresso.codeforces.com/7289e8895d0dd56c47b6b17969b9cf77b36786b5.png)\n\nOn second step we color all vertices in the subtree of vertex 3 into color 1:\n\n![image](https://espresso.codeforces.com/819001df7229138db3a407713744d1e3be88b64e.png)\n\nOn third step we color all vertices in the subtree of vertex 6 into color 2:\n\n![image](https://espresso.codeforces.com/80ebbd870a0a339636a21b9acdaf9de046458b43.png)\n\nOn fourth step we color all vertices in the subtree of vertex 4 into color 1:\n\n![image](https://espresso.codeforces.com/ed836aa723ac0176abde4e32988e3ac205014e93.png)\n\nOn fith step we color all vertices in the subtree of vertex 7 into color 3:\n\n![image](https://espresso.codeforces.com/8132909e11b41c27b8df2f0b0c10bc841f35e58a.png)"}],"translated_statement":[{"iden":"statement","content":"你被给定一棵包含 #cf_span[n] 个顶点的有根树。顶点编号从 #cf_span[1] 到 #cf_span[n]，根是编号为 #cf_span[1] 的顶点。\n\n每个顶点有一个颜色，记顶点 #cf_span[v] 的颜色为 #cf_span[cv]。初始时 #cf_span[cv = 0]。\n\n你需要用最少的步数将树染成给定的颜色。每一步，你可以选择一个顶点 #cf_span[v] 和一种颜色 #cf_span[x]，然后将 #cf_span[v] 的子树中所有顶点（包括 #cf_span[v] 自身）染成颜色 #cf_span[x]。换句话说，对于每一个顶点 #cf_span[u]，如果从根到 #cf_span[u] 的路径经过 #cf_span[v]，则设置 #cf_span[cu = x]。\n\n保证你需要将每个顶点染成不同于 #cf_span[0] 的颜色。\n\n你可以通过以下链接了解什么是有根树：https://en.wikipedia.org/wiki/Tree_(graph_theory)。\n\n第一行包含一个整数 #cf_span[n] (#cf_span[2 ≤ n ≤ 104]) —— 树中顶点的数量。\n\n第二行包含 #cf_span[n - 1] 个整数 #cf_span[p2, p3, ..., pn] (#cf_span[1 ≤ pi < i])，其中 #cf_span[pi] 表示顶点 #cf_span[i] 和 #cf_span[pi] 之间有一条边。\n\n第三行包含 #cf_span[n] 个整数 #cf_span[c1, c2, ..., cn] (#cf_span[1 ≤ ci ≤ n])，其中 #cf_span[ci] 是你应该将第 #cf_span[i] 个顶点染成的颜色。\n\n保证给定的图是一棵树。\n\n请输出一个整数 —— 将树染成给定颜色所需的最少步数。\n\n第一个样例中的树如图所示（数字为顶点编号）：\n\n\n\n第一步，我们将顶点 #cf_span[1] 的子树中所有顶点染成颜色 #cf_span[2]（数字为颜色）：\n\n\n\n第二步，我们将顶点 #cf_span[5] 的子树中所有顶点染成颜色 #cf_span[1]：\n\n\n\n第三步，我们将顶点 #cf_span[2] 的子树中所有顶点染成颜色 #cf_span[1]：\n\n\n\n第二个样例中的树如图所示（数字为顶点编号）：\n\n\n\n第一步，我们将顶点 #cf_span[1] 的子树中所有顶点染成颜色 #cf_span[3]（数字为颜色）：\n\n\n\n第二步，我们将顶点 #cf_span[3] 的子树中所有顶点染成颜色 #cf_span[1]：\n\n\n\n第三步，我们将顶点 #cf_span[6] 的子树中所有顶点染成颜色 #cf_span[2]：\n\n\n\n第四步，我们将顶点 #cf_span[4] 的子树中所有顶点染成颜色 #cf_span[1]：\n\n\n\n第五步，我们将顶点 #cf_span[7] 的子树中所有顶点染成颜色 #cf_span[3]：\n\n\n\n"},{"iden":"input","content":"第一行包含一个整数 #cf_span[n] (#cf_span[2 ≤ n ≤ 104]) —— 树中顶点的数量。第二行包含 #cf_span[n - 1] 个整数 #cf_span[p2, p3, ..., pn] (#cf_span[1 ≤ pi < i])，其中 #cf_span[pi] 表示顶点 #cf_span[i] 和 #cf_span[pi] 之间有一条边。第三行包含 #cf_span[n] 个整数 #cf_span[c1, c2, ..., cn] (#cf_span[1 ≤ ci ≤ n])，其中 #cf_span[ci] 是你应该将第 #cf_span[i] 个顶点染成的颜色。保证给定的图是一棵树。 "},{"iden":"output","content":"请输出一个整数 —— 将树染成给定颜色所需的最少步数。"},{"iden":"examples","content":"输入61 2 2 1 52 1 1 1 1 1输出3输入71 1 2 3 1 43 3 1 1 1 2 3输出5"},{"iden":"note","content":"第一个样例中的树如图所示（数字为顶点编号）：第一步，我们将顶点 #cf_span[1] 的子树中所有顶点染成颜色 #cf_span[2]（数字为颜色）：第二步，我们将顶点 #cf_span[5] 的子树中所有顶点染成颜色 #cf_span[1]：第三步，我们将顶点 #cf_span[2] 的子树中所有顶点染成颜色 #cf_span[1]：第二个样例中的树如图所示（数字为顶点编号）：第一步，我们将顶点 #cf_span[1] 的子树中所有顶点染成颜色 #cf_span[3]（数字为颜色）：第二步，我们将顶点 #cf_span[3] 的子树中所有顶点染成颜色 #cf_span[1]：第三步，我们将顶点 #cf_span[6] 的子树中所有顶点染成颜色 #cf_span[2]：第四步，我们将顶点 #cf_span[4] 的子树中所有顶点染成颜色 #cf_span[1]：第五步，我们将顶点 #cf_span[7] 的子树中所有顶点染成颜色 #cf_span[3]："}],"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the number of vertices in a rooted tree, with root at vertex $ 1 $.  \nLet $ P = (p_2, p_3, \\dots, p_n) $, where $ p_i \\in \\{1, \\dots, i-1\\} $, define the parent of vertex $ i $ for $ i = 2, \\dots, n $.  \nLet $ C = (c_1, c_2, \\dots, c_n) $, where $ c_i \\in \\{1, \\dots, n\\} $, be the target color of vertex $ i $.  \nLet $ T = (V, E) $ be the tree with $ V = \\{1, 2, \\dots, n\\} $ and edges $ \\{(i, p_i) \\mid i = 2, \\dots, n\\} $.  \n\n**Constraints**  \n1. $ 2 \\leq n \\leq 10^4 $  \n2. $ 1 \\leq p_i < i $ for all $ i = 2, \\dots, n $  \n3. $ 1 \\leq c_i \\leq n $ for all $ i = 1, \\dots, n $  \n4. Initially, all vertices have color $ 0 $.  \n\n**Objective**  \nFind the minimum number of operations required to transform the initial coloring (all 0s) into the target coloring $ C $, where each operation consists of selecting a vertex $ v $ and a color $ x $, and coloring the entire subtree rooted at $ v $ with color $ x $.","simple_statement":null,"has_page_source":false}