Count Nodes Greater Than Parent
You are given a tree where nodes are numbered from 0 to N-1. The tree structure is described using a parent array P of size N. For each node i (from 1 to N-1), P[i] is the parent of node i. Node 0 is the root and has no parent (represented by P[0] = -1). You are also given an array V of size N, where V[i] is the value of node i. Your task is to count how many nodes in the tree have a value strictly greater than their parent's value. The root node (node 0) has no parent, so it cannot be counted.
Input
The first line contains an integer N. The second line contains N integers representing the parent array P, where P[0] is always -1. The third line contains N integers representing the value array V.
Output
Print a single integer: the count of nodes whose value is strictly greater than their parent's value.
Constraints
1 <= N <= 1000 -1 <= P[i] < i for 1 <= i < N P[0] = -1 0 <= V[i] <= 10^9
Example 1
5 -1 0 0 1 1 10 5 15 7 12
3
Node 2 (value 15) > parent 0 (value 10). Node 4 (value 12) > parent 1 (value 5). Count = 2.
Example 2
3 -1 0 0 5 8 3
1
Node 1 (value 8) > parent 0 (value 5). Node 2 (value 3) is not > parent 0 (value 5). Count = 1.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
5 -1 0 0 1 1 10 5 15 7 12
3 -1 0 0 5 8 3