import java.util.ArrayList; public class CycleDetection { private Graph G; private boolean[] visited; private boolean hasCycle = false; public CycleDetection(Graph G){ if(G.isDirected()) throw new IllegalArgumentException("只支持无向图"); this.G = G; visited = new boolean[G.V()]; // 多包一层for,防止有多个联通分量 for(int v = 0 ;v