An Optimal Algorithm for Scanning All Spanning Trees of Undirected Graphs