题解思路:
因为一次能染一棵子树,所以只要有一个点和他的父节点的颜色不一样,那么就要染一次,然后答案加一就可以了。
$\texttt{AC}\ \texttt{CODE:}$
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 10010;
int n;
int p[N], c[N];
int main(){
scanf("%d", &n);
for (int i = 2; i <= n; i ++ ) scanf("%d", &p[i]);
for (int i = 1; i <= n; i ++ ) scanf("%d", &c[i]);
int res = 1;//根节点染一次
for (int i = 2; i <= n; i ++ )
if (c[i] != c[p[i]])//要染一次
res ++;//答案加一
printf("%d\n", res);//输出
return 0;
}
# ${\Huge 求赞}$
# ${\huge 求赞} $
# ${\LARGE 求赞} $
# ${\Large 求赞}$
# ${\large 求赞} $
# ${\normalsize 求赞}$
# ${\small 求赞} $
# ${\scriptsize 求赞} $
# ${\tiny 求赞}$
## ${\Huge 求赞}$
## ${\huge 求赞} $
## ${\LARGE 求赞} $
## ${\Large 求赞}$
## ${\large 求赞} $
## ${\normalsize 求赞}$
## ${\small 求赞} $
## ${\scriptsize 求赞} $
## ${\tiny 求赞}$
${\Huge 求赞}$
${\huge 求赞} $
${\LARGE 求赞} $
${\Large 求赞}$
${\large 求赞} $
${\normalsize 求赞}$
${\small 求赞} $
${\scriptsize 求赞} $
${\tiny 求赞}$
${\Huge 求赞}$
${\huge 求赞} $
${\LARGE 求赞} $
${\Large 求赞}$
${\large 求赞} $
${\normalsize 求赞}$
${\small 求赞} $
${\scriptsize 求赞} $
${\tiny 求赞}$
# 求赞