We want to find the shortest path between two points in a special grid. We can travel between adjacent squares in a single move, but we can also travel between cells of the same type (there are 10 types) in a single move no matter the distance between them.
How can we find the the number of steps required to travel between two points for a grid of up to 100×100 in size?
Make 10 arrays, each one containing the cells of corresponding type. Now run Dijkstra (or BFS), but when you visit a cell of type
i, add all cells of typeito the queue and clear the corresponding array. This way you don’t have to visit every edge between cells of the same type and the complexity is O(n^2) instead of O(n^4)