Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Reach Destination in Time

Try to solve the Minimum Cost to Reach Destination in Time problem.

Statement

There is a country with n cities labeled from 00 to n −1- 1. The country has bidirectional roads represented by an array edges, where edges[i] = [xi,yi,timei][x_i, y_i, {time}_i] denotes a road connecting city xix_i and city yiy_i that requires timei {time}_i minutes to traverse.

You are given an integer array passingFees of length n, where passingFees[j] is the fee required to visit city jj, and an integer maxTime.

You start at city 00 and wish to reach city n −1- 1. The total cost of a path is the sum of the passing fees for all cities visited along the route, including city 00 and city n −1- 1.

Return the minimum cost to travel from city 00 to city n −1- 1 such that the total travel time is at most maxTime. If no such route exists within the given time limit, return −1-1.

Constraints:

  • 1≤1 \leq maxTime ≤1000\leq 1000

  • n ==== passingFees.length

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

  • n −1≤- 1 \leq edges.length ≤1000\leq 1000

  • 0≤xi,yi≤0 \leq x_i, y_i \leq n −1- 1

  • 1≤timei≤10001 \leq {time}_i \leq 1000

  • 1≤1 \leq passingFees[j] ≤1000\leq 1000

  • The graph may contain multiple edges between two nodes.

  • The graph does not contain self loops.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Reach Destination in Time

Try to solve the Minimum Cost to Reach Destination in Time problem.

Statement

There is a country with n cities labeled from 00 to n −1- 1. The country has bidirectional roads represented by an array edges, where edges[i] = [xi,yi,timei][x_i, y_i, {time}_i] denotes a road connecting city xix_i and city yiy_i that requires timei {time}_i minutes to traverse.

You are given an integer array passingFees of length n, where passingFees[j] is the fee required to visit city jj, and an integer maxTime.

You start at city 00 and wish to reach city n −1- 1. The total cost of a path is the sum of the passing fees for all cities visited along the route, including city 00 and city n −1- 1.

Return the minimum cost to travel from city 00 to city n −1- 1 such that the total travel time is at most maxTime. If no such route exists within the given time limit, return −1-1.

Constraints:

  • 1≤1 \leq maxTime ≤1000\leq 1000

  • n ==== passingFees.length

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

  • n −1≤- 1 \leq edges.length ≤1000\leq 1000

  • 0≤xi,yi≤0 \leq x_i, y_i \leq n −1- 1

  • 1≤timei≤10001 \leq {time}_i \leq 1000

  • 1≤1 \leq passingFees[j] ≤1000\leq 1000

  • The graph may contain multiple edges between two nodes.

  • The graph does not contain self loops.