Skip to content

Practice Second Minimum Time to Reach Destination

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2045
LeetCode Problem

Second Minimum Time to Reach Destination

Problem Statement

The graph has n vertices and each edges[i] = [u,v] is an undirected connection. Travel from vertex 1 to n in the undirected graph, taking time minutes per edge. All signals begin green and switch together every change minutes. You may enter on either color but can depart only on green, and must depart immediately when green. Revisiting any vertex is allowed. Return the smallest arrival time strictly greater than the minimum possible arrival time.

Source: Second Minimum Time to Reach Destination on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 5, edges = [[1,2],[1,3],[1,4],[3,4],[4,5]], time = 3, change = 5
Output
13

# Example 2

Input
n = 2, edges = [[1,2]], time = 3, change = 2
Output
11

Constraints

2 <= n <= 10^4
n - 1 <= edges.length <= min(2 * 10^4, n * (n - 1) / 2)
edges[i].length == 2
1 <= ui, vi <= n
ui != vi
There are no duplicate edges.
Each vertex can be reached directly or indirectly from every other vertex.
1 <= time, change <= 10^3

Related LeetCode Problems

Practice more problems similar to Second Minimum Time to Reach Destination.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.