#K46892. Salary Supervisor Check

    ID: 28077 Type: Default 1000ms 256MiB

Salary Supervisor Check

Salary Supervisor Check

You are given a company structure with (N) employees. Each employee has a supervisor and a salary. A valid salary distribution requires that every supervisor earns at least as much as each of their direct subordinates. In other words, for every employee (i) with supervisor (p_i) (where (p_i \neq -1)), the following condition must hold: $$S_{p_i} \ge S_i.$$

Your task is to determine whether the given salary distribution is valid.

inputFormat

The first line contains an integer (N), the number of employees. The second line contains (N) space-separated integers representing the supervisor for each employee (with -1 indicating no supervisor). The third line contains (N) space-separated integers representing the salary of each employee. Note: For employees with a valid supervisor (i.e. not -1), the supervisor index is 1-indexed.

outputFormat

Output a single line containing either "YES" if the salary distribution is valid, or "NO" otherwise.## sample

6
-1 1 1 2 2 3
3000 2000 2500 1800 1700 1600
YES