Skip to content

Practice Minimize the Maximum Edge Weight of Graph

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

Medium#3419
LeetCode Problem

Minimize the Maximum Edge Weight of Graph

Problem Statement

Given a directed graph with edges [from, to, weight], n nodes numbered 0 through n - 1, and threshold, remove edges so that every node can reach node 0 and every node has at most threshold outgoing edges. Among graphs meeting both conditions, minimize the largest remaining edge weight. Return that minimum, or -1 if impossible.

Source: Minimize the Maximum Edge Weight of Graph on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 5, edges = [[1,0,1],[2,0,2],[3,0,1],[4,3,1],[2,1,1]], threshold = 2
Output
1

# Example 2

Input
n = 5, edges = [[0,1,1],[0,2,2],[0,3,1],[0,4,1],[1,2,1],[1,4,1]], threshold = 1
Output
-1

# Example 3

Input
n = 5, edges = [[1,2,1],[1,3,3],[1,4,5],[2,3,2],[3,4,2],[4,0,1]], threshold = 1
Output
2

# Example 4

Input
n = 5, edges = [[1,2,1],[1,3,3],[1,4,5],[2,3,2],[4,0,1]], threshold = 1
Output
-1

Constraints

2 <= n <= 10^5
1 <= threshold <= n - 1
1 <= edges.length <= min(10^5, n * (n - 1) / 2).
edges[i].length == 3
0 <= Ai, Bi < n
Ai != Bi
1 <= Wi <= 10^6
There may be multiple edges between a pair of nodes, but they must have unique weights.

Related LeetCode Problems

Practice more problems similar to Minimize the Maximum Edge Weight of Graph.

Review your practice with PhantomCodeAI

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