3977. Minimum Time to Reach Target With Limited Power
You are given a directed weighted graph with
nnodes labeled from 0 ton - 1.The graph is represented by a 2D integer array
edges, whereedges[i] = [u_i, v_i, t_i]indicates a directed edge from nodeu_ito nodev_ithat takest_iseconds to traverse.You are also given an integer
powerrepresenting the initial available power, and an integer arraycostof lengthn, wherecost[u]represents the power required to forward the signal from nodeuthrough any one of its outgoing edges.You are given two integers
sourceandtarget.The signal starts at
sourceat time 0 withpowerunits of power and follows these rules:
- The signal may traverse a directed edge from node
uonly if the remaining power is at leastcost[u].- No power is consumed when the signal arrives at a node, unless it later leaves that node by traversing another edge.
- When the signal is forwarded from node
u, the remaining power is decreased bycost[u]units.- Traversing an edge
edges[i] = [u_i, v_i, t_i]increases the total time byt_iseconds.Return an integer array
answerof size 2, where:
answer[0]is the minimum time required for the signal to reach nodetarget.answer[1]is the maximum remaining power among all paths that achieveanswer[0].If the signal cannot reach
target, return[-1, -1].
1 |
|