Traffic signal shortest arrival
Your task
A courier travels a road network of n intersections (0..n-1) connected by bidirectional roads [u, v, travel_time]. Every intersection has a synchronized signal: during the first red_period time units of each 2*red_period cycle it is green (you may depart), and during the second half it is red (you must wait at the intersection until the next green). The courier starts at intersection 0 at time 0 (green) and wants to reach intersection n-1. Return the earliest arrival time, or -1 if unreachable. Arriving at an intersection is always allowed; only departing is gated.
Examples
min_time_signals(n: int, roads: list[list[int]], red_period: int) -> intExample 1
Input
min_time_signals(3, [[0, 1, 7], [1, 2, 4]], 5)Output
14