start = [x, y] and want to reach point finish. Walking from (x1, y1) to (x2, y2) costs |x2 - x1| + |y2 - y1|.
There are also tunnels: tunnels[i] = [x1, y1, x2, y2, cost] is a one-way tunnel from (x1, y1) to (x2, y2) that costs cost to ride. Each tunnel can be used any number of times, or not at all.
Return the minimum cost of getting from start to finish.start=[1, 1], finish=[9, 3], tunnels=[[2, 1, 8, 3, 2], [8, 3, 1, 1, 1]] → 4
Walk to the first tunnel's entrance (2, 1) for 1, ride it for 2, then walk from its exit (8, 3) to the finish for 1. That is 4 instead of 10 on foot. The second tunnel goes the other way and does not help.
start=[5, 5], finish=[6, 7], tunnels=[[5, 5, 6, 7, 10]] → 3
The tunnel costs 10, while walking takes only |6 − 5| + |7 − 5| = 3.
start=[1, 1], finish=[20, 20], tunnels=[[1, 2, 10, 10, 3], [10, 11, 20, 19, 3], [12, 12, 1, 1, 1]] → 9
start=[1, 1], finish=[9, 3], tunnels=[[2, 1, 8, 3, 2], [8, 3, 1, 1, 1]]
4
Run checks the first 3 tests in your browser. Submit checks all 57 tests on the server, hidden ones included.