Find the path from source to destination with fewest stations, then fewest roads, under refueling rules.
Unlock detailed company stats for this questionUpgrade
You are given N cities and M roads, each road connecting two different cities directly. Going by car from city x to city y via any road costs 1 kg of fuel. The car starts at the source city and must reach the destination city, initially with P kg of fuel. Some cities have refueling stations: whenever you visit a city with a station, you must refuel to exactly P kg again. You may visit the same road multiple times, and each visit counts separately in the final answer. The source city is never a station.
Priorities, in order:
- Never reach negative fuel at any point.
- Visit the minimum number of stations.
- Use the minimum number of direct roads.
Output {min_stations, min_roads} for the path, and report if it is not possible (you might run out of fuel on the way).
Format · Onsite DSA round.
Community answers
No answers contributed by the community yet.


