Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- vector<int>edge[10001];
- int ans=0;
- int v[10001];
- int color[10001];
- void dfs(int x)
- {
- if(v[x]==1) return;
- v[x]=1;
- for(auto z:edge[x])
- {
- if(!v[z])
- {
- if(color[z]!=color[x])
- {
- ans++;
- }
- dfs(z);
- }
- }
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);cout.tie(0);
- int n,i,j;
- cin>>n;
- for(i=2;i<=n;i++)
- {
- int k;
- cin>>k;
- edge[i].push_back(k);
- edge[k].push_back(i);
- }
- for(i=1;i<=n;i++)
- {
- cin>>color[i];
- }
- memset(v,0,sizeof(v));
- dfs(1);
- cout<<ans+1<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement