You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// You are given a directed acyclic graph of n nodes numbered from 0 to n − 1. This is represented by a 2D array edges of length m, where edges[i] = [ui, vi, costi] indicates a one‑way communication from node ui to node vi with a recovery cost of costi.
3
+
// Some nodes may be offline. You are given a boolean array online where online[i] = true means node i is online. Nodes 0 and n − 1 are always online.
4
+
// A path from 0 to n − 1 is valid if:
5
+
// All intermediate nodes on the path are online.
6
+
// The total recovery cost of all edges on the path does not exceed k.
7
+
// For each valid path, define its score as the minimum edge‑cost along that path.
8
+
// Return the maximum path score (i.e., the largest minimum-edge cost) among all valid paths. If no valid path exists, return -1.
9
+
10
+
11
+
// Solution: Binary Search & Topological Sort
12
+
13
+
// Binary search for the maximum minimum edge cost.
14
+
// For a minimum edge cost x, use topological sort to check if we can reach n-1 in less than k total score.
15
+
16
+
// Start off with nodes with no inbound edges.
17
+
// Traverse neighbor nodes and only queue the neighbor if we have used all inbound edges.
18
+
// Record the minimum cost to reach each node.
19
+
20
+
// Note: This solution is TLE, passes 626/636 test cases.
21
+
// n = number of nodes, m = max(edge cost), e = number of edges
0 commit comments