You are given an integer
nrepresenting the number of tasks in a project, numbered from 0 ton - 1. These tasks are connected as a tree rooted at task 0. This is represented by a 2D integer arrayedgesof lengthn - 1, whereedges[i] = [u_i, v_i]indicates that tasku_iis the parent of taskv_i.You are also given an array
baseTimeof lengthn, wherebaseTime[i]represents the time to complete taski.The finish time of each task is calculated as follows:
- Leaf task: The finish time is
baseTime[i].- Non-leaf task:
- Let
earliestbe the minimum finish time among its children, andlatestbe the maximum finish time among its children.- Let
ownDurationbe(latest - earliest) + baseTime[i].- The finish time of task
iislatest + ownDuration.Return the finish time of the root task 0.
1 | class Solution { |