Resolution now uses a priority queue instead of stack