Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Repair Edges to Traverse a Graph

Try to solve the Minimum Cost to Repair Edges to Traverse a Graph problem.

Statement

You are given an integer n representing the number of nodes in an undirected graph, labeled from 00 to n−1n - 1. You are also given a 22D integer array edges, where edges[i] =[ui,vi,wi]= [u_i, v_i, w_i] indicates an undirected edge between node uiu_i and node viv_i with a repair cost of wiw_i. Additionally, you are given an integer k.

To traverse an edge, it must be repaired. If you have an amount of money equal to CC, you can repair and use any edge with a repair cost of at most CC.

Return the minimum amount of money required to travel from node 00 to node n−1n - 1 along a path containing at most k edges. If it is impossible to reach node n−1n - 1 from node 00 using at most k edges, return −1-1.

Constraints:

  • 2≤2 \le n ≤5imes104\le 5 imes 10^4

  • 1≤1 \le edges.length =m≤105= m \le 10^5

  • edges[i] =[ui,vi,wi]= [u_i, v_i, w_i]

  • 0≤ui,vi<0 \le u_i, v_i < n

  • 1≤wi≤1091 \le w_i \le 10^9

  • 1≤1 \le k ≤\le n

  • There are no self loops or duplicate edges in the graph.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Repair Edges to Traverse a Graph

Try to solve the Minimum Cost to Repair Edges to Traverse a Graph problem.

Statement

You are given an integer n representing the number of nodes in an undirected graph, labeled from 00 to n−1n - 1. You are also given a 22D integer array edges, where edges[i] =[ui,vi,wi]= [u_i, v_i, w_i] indicates an undirected edge between node uiu_i and node viv_i with a repair cost of wiw_i. Additionally, you are given an integer k.

To traverse an edge, it must be repaired. If you have an amount of money equal to CC, you can repair and use any edge with a repair cost of at most CC.

Return the minimum amount of money required to travel from node 00 to node n−1n - 1 along a path containing at most k edges. If it is impossible to reach node n−1n - 1 from node 00 using at most k edges, return −1-1.

Constraints:

  • 2≤2 \le n ≤5imes104\le 5 imes 10^4

  • 1≤1 \le edges.length =m≤105= m \le 10^5

  • edges[i] =[ui,vi,wi]= [u_i, v_i, w_i]

  • 0≤ui,vi<0 \le u_i, v_i < n

  • 1≤wi≤1091 \le w_i \le 10^9

  • 1≤1 \le k ≤\le n

  • There are no self loops or duplicate edges in the graph.