You are given an integer
nrepresenting the number of tasks in a project, numbered from 0 ton - 1. These tasks are connected as an undirectedtree. This is represented by a 2D integer arrayedgesof lengthn - 1, whereedges[i] = [u_i, v_i]indicates an undirected connection between tasku_iand taskv_i.You are also given an array
baseTimeof lengthn, wherebaseTime[i]represents the time to complete taski.For any chosen task as the root, 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].- Finish time of task
iislatest + ownDuration.Choose any task as the root and compute the finish time of that root based on the rules above.
Return the minimum possible finish time among all choices of root.
1 | vector<vector<pair<long long, long long>>> mas, mis; |