2

Imagine we have some cells, and you can teleport in other cells through portals, there exists some "teleporting" time for every cell, but there are also some guardians, while a guardians is in the cell you're in you have to wait until the moment he leaves so you could teleport into another cell. Find the minimum time spent to escape the prison.

To summarize: We have an undirected graph with costs, but also a restraint that if a guardian is in a cell you have to wait until he leaves so you can teleport.

What I did:

I did the usual dijkstra's algorithm but at every normal cost, I checked if at that cost: "is there a guardian in that cell?" and if so, i would check for how many seconds, and add that to the minimum time. Dijkstra is implemented with min-heap, and I check for guardians using a binary search tree based on the moments given. Also there can be more than 1 cell from which you can escape, and I use binary search trees also to store every cell that you can escape from so that i can search for the "minimum of all the minimums".

Can you optimize this more than that? I mean I use binary search trees, min-heaps, what can take so long? (for a graph with 5000 vertices and around 6000 edges)

J. Homer
  • 157
  • 11

0 Answers0