H:有趣的试剂(1317)

题目链接:http://acm.xidian.edu.cn/problem.php?id=1317

原题链接:http://codeforces.com/problemset/problem/902/B(看不懂题目的,可以去看原题,下面有样例说明)

  核心就是他是一棵树,你总是要从上往下染;

 1 #include<stdio.h>
 2 
 3 int n,ans;
 4 int father[10004];
 5 int clour[10004];
 6 int main()
 7 {
 8     int T;
 9     scanf("%d",&T);
10     while(T--)
11     {
12         ans = 1;
13         scanf("%d",&n);
14         for(int i = 2;i <= n;i++)
15             scanf("%d",&father[i]);
16             
17         for(int i = 1;i <= n;i++)
18             scanf("%d",&clour[i]);
19             
20         for(int i = 2;i <= n;i++)
21         {
22             if(clour[i] != clour[father[i]])
23                 ans++;
24         }
25         printf("%d\n",ans);
26     }
27     return 0;
28 } 

 

  别人说明:https://blog.csdn.net/m0_37809890/article/details/78856185

posted @ 2018-05-31 01:23  Dicer  阅读(182)  评论(0编辑  收藏  举报