Tap here to switch tabs
Problem
Submissions

Problem: Time Needed to Inform All Employees

med
30 min
Try to solve the Time Needed to Inform All Employees problem.

Statement

A company has n employees, uniquely identified with IDs from 00 to n - 1. The head of the company has the ID headID.

Each employee i has a direct manager specified by manager[i]. The head of the company has no manager, so manager[headID] is equal to −1-1. The managerial structure forms a tree rooted at headID.

When an employee receives urgent news, they will inform all of their direct subordinates simultaneously. The time it takes for employee i to inform all of their direct subordinates is informTime[i] minutes.

Given n, headID, manager, and informTime, return the total number of minutes needed to inform all employees in the company.

Constraints:

  • 1≤1 \leq n ≤105\leq 10^5

  • 0≤0 \leq headID << n

  • manager.length ==== n

  • 0≤0 \leq manager[i] << n for all i where i ≠\neq headID

  • manager[headID] ==−1== -1

  • informTime.length ==== n

  • 0≤0 \leq informTime[i] ≤1000\leq 1000

  • informTime[i] ==0== 0 if employee i has no subordinates.

  • It is guaranteed that all employees can be informed.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Time Needed to Inform All Employees

med
30 min
Try to solve the Time Needed to Inform All Employees problem.

Statement

A company has n employees, uniquely identified with IDs from 00 to n - 1. The head of the company has the ID headID.

Each employee i has a direct manager specified by manager[i]. The head of the company has no manager, so manager[headID] is equal to −1-1. The managerial structure forms a tree rooted at headID.

When an employee receives urgent news, they will inform all of their direct subordinates simultaneously. The time it takes for employee i to inform all of their direct subordinates is informTime[i] minutes.

Given n, headID, manager, and informTime, return the total number of minutes needed to inform all employees in the company.

Constraints:

  • 1≤1 \leq n ≤105\leq 10^5

  • 0≤0 \leq headID << n

  • manager.length ==== n

  • 0≤0 \leq manager[i] << n for all i where i ≠\neq headID

  • manager[headID] ==−1== -1

  • informTime.length ==== n

  • 0≤0 \leq informTime[i] ≤1000\leq 1000

  • informTime[i] ==0== 0 if employee i has no subordinates.

  • It is guaranteed that all employees can be informed.