Question: icon - menu link - logo question search Sign In Homework Help > Science > Computer Science You are given a tree consisting of N
iconmenu
linklogo
question search
Sign In
Homework HelpScienceComputer Science
You are given a tree consisting of N nodes You are also given two arrays A and P of size N each where the value Ai denotes the value written on the ith node and the value Pi denotes that there is an
Question
You are given a tree consisting of N nodes
You are also given two arrays A and P of size N each, where the value Ai denotes the value written on the ith node and the value Pi denotes that there is an edge between the node i and Pi
We say that an edge is considered good, if after deleting this edge this will result in formation of trees the values in each of the nodes of the trees are distinct.
Find the total number of good edges present in tree.
Input format:
The first line contains an integer, N denoting the number of elements in A
Each line i of the N subsequent lines where i N contains an integer describing Ai
Each line i of the N subsequent lines where i N contains an integer describing Pi
Constraints:
N
Ai
Pi
Sample Test Cases:
Case :
Input :
Output:
Explanation:
Given N A P
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
