public LazyPrimMST(EdgeWeightedGraph g) { _mst = new List <Edge>(); _pq = new List <Edge>(); _marked = new bool[g.Vertice()]; Visit(g, 0); while (_pq.Count != 0) { Edge e = ReturnEdgeWithLowestWeight(); int v = e.Either(), w = e.Other(v); if (_marked[v] && _marked[w]) { continue; } _mst.Add(e); if (!_marked[v]) { Visit(g, v); } if (!_marked[w]) { Visit(g, w); } } _mst.Reverse(); }
public void AddEdge(Edge e) { int v = e.Either(), w = e.Other(v); adj[v].Add(e); adj[w].Add(e); _edge++; }