Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Reach City With Discounts

Try to solve the Minimum Cost to Reach City With Discounts problem.

Statement

You are given an integer n representing the number of cities labeled from 00 to n −1- 1, and a 2D2 {D} integer array highways, where highways[i] = [‘city1i‘,‘city2i‘,‘tolli‘][`city1_i`, `city2_i`, `toll_i`] indicates a bidirectional highway connecting city1_i and city2_i with a toll cost of toll_i. You are also given an integer discounts, which denotes the maximum number of discount coupons you can use.

Applying a discount to a highway halves its toll, rounded down to the nearest integer (that is, ⌊toll/2⌋\lfloor {toll} / 2 \rfloor). You can use at most one discount coupon on any single highway traversal, and you may use at most discounts coupons during the entire journey.

Return the minimum total cost to travel from city 00 to city n −1- 1. If city n −1- 1 cannot be reached from city 00, return −1-1.

Constraints:

  • 2≤2 \leq n ≤1000\leq 1000

  • 1≤1 \leq highways.length ≤1000\leq 1000

  • highways[i].length =3= 3

  • 0≤0 \leq city1_i, city2_i ≤\leq n −1- 1

  • city1_i ≠\neq city2_i

  • 0≤0 \leq toll_i ≤105\leq 10^5

  • 0≤0 \leq discounts ≤500\leq 500

  • There are no duplicate highways.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Reach City With Discounts

Try to solve the Minimum Cost to Reach City With Discounts problem.

Statement

You are given an integer n representing the number of cities labeled from 00 to n −1- 1, and a 2D2 {D} integer array highways, where highways[i] = [‘city1i‘,‘city2i‘,‘tolli‘][`city1_i`, `city2_i`, `toll_i`] indicates a bidirectional highway connecting city1_i and city2_i with a toll cost of toll_i. You are also given an integer discounts, which denotes the maximum number of discount coupons you can use.

Applying a discount to a highway halves its toll, rounded down to the nearest integer (that is, ⌊toll/2⌋\lfloor {toll} / 2 \rfloor). You can use at most one discount coupon on any single highway traversal, and you may use at most discounts coupons during the entire journey.

Return the minimum total cost to travel from city 00 to city n −1- 1. If city n −1- 1 cannot be reached from city 00, return −1-1.

Constraints:

  • 2≤2 \leq n ≤1000\leq 1000

  • 1≤1 \leq highways.length ≤1000\leq 1000

  • highways[i].length =3= 3

  • 0≤0 \leq city1_i, city2_i ≤\leq n −1- 1

  • city1_i ≠\neq city2_i

  • 0≤0 \leq toll_i ≤105\leq 10^5

  • 0≤0 \leq discounts ≤500\leq 500

  • There are no duplicate highways.