Tap here to switch tabs
Problem
Submissions

Problem: Find Shortest Path with K Hops

Try to solve the Find Shortest Path with K Hops problem.

Statement

You are given an undirected, weighted, and connected graph with n nodes labeled from 00 to n −1- 1, and an array edges where edges[i] = [u_i, v_i, w_i] represents an edge between node u_i and node v_i with a positive weight w_i.

You are also given three integers s, d, and k, representing the starting node, the destination node, and the maximum number of hops you can make, respectively. In a single hop, you can traverse an edge and set its weight contribution to 00.

Return the minimum total weight of a path from s to d after reducing the weight of at most k traversed edges to 00.

Constraints:

  • 2≤2 \leq n ≤500\leq 500

  • n −1≤- 1 \leq edges.length ≤min⁡(104,‘n‘×(‘n‘−1)2)\leq \min(10^4, \frac{ {`n`} \times ( {`n`} - 1)}{2})

  • edges[i].length =3= 3

  • 0≤0 \leq edges[i][0], edges[i][1] ≤\leq n −1- 1

  • 1≤1 \leq edges[i][2] ≤106\leq 10^6

  • 0≤0 \leq s, d, k ≤\leq n −1- 1

  • s ≠\neq d

  • The graph is connected and contains no repeated edges or self loops.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find Shortest Path with K Hops

Try to solve the Find Shortest Path with K Hops problem.

Statement

You are given an undirected, weighted, and connected graph with n nodes labeled from 00 to n −1- 1, and an array edges where edges[i] = [u_i, v_i, w_i] represents an edge between node u_i and node v_i with a positive weight w_i.

You are also given three integers s, d, and k, representing the starting node, the destination node, and the maximum number of hops you can make, respectively. In a single hop, you can traverse an edge and set its weight contribution to 00.

Return the minimum total weight of a path from s to d after reducing the weight of at most k traversed edges to 00.

Constraints:

  • 2≤2 \leq n ≤500\leq 500

  • n −1≤- 1 \leq edges.length ≤min⁡(104,‘n‘×(‘n‘−1)2)\leq \min(10^4, \frac{ {`n`} \times ( {`n`} - 1)}{2})

  • edges[i].length =3= 3

  • 0≤0 \leq edges[i][0], edges[i][1] ≤\leq n −1- 1

  • 1≤1 \leq edges[i][2] ≤106\leq 10^6

  • 0≤0 \leq s, d, k ≤\leq n −1- 1

  • s ≠\neq d

  • The graph is connected and contains no repeated edges or self loops.