n stations numbered 0 to n - 1, and some pairs of stations are joined by tunnels. A tunnel tunnels[i] = [u, v, c] joins stations u and v and holds c checkpoints placed in a chain: u → checkpoint 1 → … → checkpoint c → v (with c = 0 the stations are joined directly).
One step moves between neighbouring objects of a chain (a station and a checkpoint, two checkpoints, or two stations when c = 0). Tunnels can be walked in both directions.
You start at station 0 and may take at most budget steps. An object (a station or a checkpoint) is reachable if you can get to it in at most budget steps. Return the number of reachable objects, counting station 0 itself.tunnels=[[0, 1, 3], [1, 2, 0]], budget=5, n=3 → 6
From station 0, four steps reach station 1, passing all 3 checkpoints, and one more step reaches station 2. That is 3 stations and 3 checkpoints: 6.
tunnels=[[0, 1, 4], [0, 2, 4], [1, 2, 4]], budget=3, n=3 → 7
The other stations are out of reach, but along each of the two tunnels leaving station 0 you can pass 3 checkpoints: 1 + 3 + 3 = 7.
tunnels=[[1, 2, 5]], budget=100, n=3 → 1
Station 0 has no tunnels, so only the station itself is reachable.
tunnels=[[0, 1, 3], [1, 2, 0]], budget=5, n=3
6
Run checks the first 3 tests in your browser. Submit checks all 106 tests on the server, hidden ones included.