Added memoization 4 keeping id of set with shortest path, bugs to fix