DFS Approach

When a vertex is discovered, it is not necessarily discovered using the shortest path from S: