A company has n employees with unique IDs from 0 to n - 1. The head of the company has ID headID.
Each employee has one direct manager given in the manager array where manager[i] is the direct manager of the i-th employee, and manager[headID] = -1. The subordination relationships form a tree structure.
The head wants to inform all employees of urgent news. He will inform his direct subordinates, and they will inform their subordinates, and so on until all employees know the news.
The i-th employee needs informTime[i] minutes to inform all direct subordinates. After informTime[i] minutes, all direct subordinates can start spreading the news.
Return the number of minutes needed to inform all employees about the urgent news.
Input & Output
Constraints
- 1 ≤ n ≤ 105
- 0 ≤ headID < n
- manager.length == n
- 0 ≤ manager[i] < n
- manager[headID] == -1
- informTime.length == n
- 0 ≤ informTime[i] ≤ 1000
- informTime[i] == 0 if employee i has no subordinates