Tap here to switch tabs
Problem
Submissions

Problem: Minimize the Maximum Edge Weight of Graph

med
30 min
Try to solve the Minimize the Maximum Edge Weight of Graph problem.

Statement

You are given an integer n representing the number of nodes in a directed graph, labeled from 00 to n −1- 1, and an integer threshold. You are also given a 2extD2 ext{D} integer array edges, where edges[i] =[Ai,Bi,Wi]= [A_i, B_i, W_i] indicates a directed edge from node AiA_i to node BiB_i with weight WiW_i.

Your task is to select a subset of edges such that:

  • Node 00 is reachable from every other node using the selected edges.

  • The out-degree of every node in the selected set of edges is at most threshold.

  • The maximum weight among all selected edges is minimized.

Return the minimum possible value of the maximum edge weight among the chosen edges. If it is impossible to satisfy these conditions, return −1-1.

Constraints:

  • 2≤2 \leq n ≤105\leq 10^5

  • 1≤1 \leq threshold ≤\leq n −1- 1

  • 1≤1 \leq edges.length ≤min⁡(105,ext‘n‘⋅(ext‘n‘−1)2)\leq \min(10^5, \frac{ ext{`n`} \cdot ( ext{`n`} - 1)}{2})

  • edges[i].length =3= 3

  • 0≤Ai,Bi<0 \leq A_i, B_i < n

  • Ai≠BiA_i \neq B_i

  • 1≤Wi≤1061 \leq W_i \leq 10^6

  • There may be multiple edges between a pair of nodes, but they must have unique weights.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimize the Maximum Edge Weight of Graph

med
30 min
Try to solve the Minimize the Maximum Edge Weight of Graph problem.

Statement

You are given an integer n representing the number of nodes in a directed graph, labeled from 00 to n −1- 1, and an integer threshold. You are also given a 2extD2 ext{D} integer array edges, where edges[i] =[Ai,Bi,Wi]= [A_i, B_i, W_i] indicates a directed edge from node AiA_i to node BiB_i with weight WiW_i.

Your task is to select a subset of edges such that:

  • Node 00 is reachable from every other node using the selected edges.

  • The out-degree of every node in the selected set of edges is at most threshold.

  • The maximum weight among all selected edges is minimized.

Return the minimum possible value of the maximum edge weight among the chosen edges. If it is impossible to satisfy these conditions, return −1-1.

Constraints:

  • 2≤2 \leq n ≤105\leq 10^5

  • 1≤1 \leq threshold ≤\leq n −1- 1

  • 1≤1 \leq edges.length ≤min⁡(105,ext‘n‘⋅(ext‘n‘−1)2)\leq \min(10^5, \frac{ ext{`n`} \cdot ( ext{`n`} - 1)}{2})

  • edges[i].length =3= 3

  • 0≤Ai,Bi<0 \leq A_i, B_i < n

  • Ai≠BiA_i \neq B_i

  • 1≤Wi≤1061 \leq W_i \leq 10^6

  • There may be multiple edges between a pair of nodes, but they must have unique weights.