Skip to content

Practice Network Recovery Pathways

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Problem Statement

Given a directed acyclic graph with weighted edges, online flags, and a budget k, consider paths from node 0 to node n - 1. Every intermediate node must be online, and the sum of edge costs must be at most k; the two endpoints are always online. A path’s score is its smallest edge cost. Return the largest score over valid paths, or -1 if no valid path exists.

Source: Network Recovery Pathways on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
edges = [[0,1,5],[1,3,10],[0,2,3],[2,3,4]], online = [true,true,true,true], k = 10
Output
3

# Example 2

Input
edges = [[0,1,7],[1,4,5],[0,2,6],[2,3,6],[3,4,2],[2,4,6]], online = [true,true,true,false,true], k = 12
Output
6

Constraints

n == online.length
2 <= n <= 5 * 10^4
0 <= m == edges.length <= min(10^5, n * (n - 1) / 2)
edges[i] = [ui, vi, costi]
0 <= ui, vi < n
ui != vi
0 <= costi <= 10^9
0 <= k <= 5 * 10^13
online[i] is either true or false, and both online[0] and online[n − 1] are true.
The given graph is a directed acyclic graph.

Related LeetCode Problems

Practice more problems similar to Network Recovery Pathways.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.