The basic idea of converting graph to tree is to detect whether there is cycle in graph first, then take out one edge in the cycle.