Tap here to switch tabs
Problem
Submissions

Problem: Minimum Time to Reach Destination in Directed Graph

Try to solve the Minimum Time to Reach Destination in Directed Graph problem.

Statement

You are given an integer n representing the number of nodes in a directed graph labeled from 00 to n−1n - 1, and a 2D2 {D} integer array edges where edges[i] =[ui,vi,starti,endi]= [u_i, v_i, start_i, end_i].

Each entry in edges indicates a directed edge from node uiu_i to node viv_i that can only be traversed if you depart from node uiu_i at a time tt such that starti≤t≤endistart_i \leq t \leq end_i. Traversing any edge takes exactly 11 unit of time.

You start at node 00 at time t=0t = 0. You are allowed to wait at any node for any non negative amount of time.

Return the minimum time required to reach node n−1n - 1. If it is impossible to reach node n−1n - 1, return −1-1.

Constraints:

  • 1≤1 \leq n ≤105\leq 10^5

  • 0≤0 \leq edges.length ≤105\leq 10^5

  • edges[i] =[ui,vi,starti,endi]= [u_i, v_i, start_i, end_i]

  • 0≤ui,vi≤n−10 \leq u_i, v_i \leq n - 1

  • ui≠viu_i \neq v_i

  • 0≤starti≤endi≤1090 \leq start_i \leq end_i \leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Time to Reach Destination in Directed Graph

Try to solve the Minimum Time to Reach Destination in Directed Graph problem.

Statement

You are given an integer n representing the number of nodes in a directed graph labeled from 00 to n−1n - 1, and a 2D2 {D} integer array edges where edges[i] =[ui,vi,starti,endi]= [u_i, v_i, start_i, end_i].

Each entry in edges indicates a directed edge from node uiu_i to node viv_i that can only be traversed if you depart from node uiu_i at a time tt such that starti≤t≤endistart_i \leq t \leq end_i. Traversing any edge takes exactly 11 unit of time.

You start at node 00 at time t=0t = 0. You are allowed to wait at any node for any non negative amount of time.

Return the minimum time required to reach node n−1n - 1. If it is impossible to reach node n−1n - 1, return −1-1.

Constraints:

  • 1≤1 \leq n ≤105\leq 10^5

  • 0≤0 \leq edges.length ≤105\leq 10^5

  • edges[i] =[ui,vi,starti,endi]= [u_i, v_i, start_i, end_i]

  • 0≤ui,vi≤n−10 \leq u_i, v_i \leq n - 1

  • ui≠viu_i \neq v_i

  • 0≤starti≤endi≤1090 \leq start_i \leq end_i \leq 10^9