Esempio n. 1
0
        public void RemoveEdge(T vertex1, T vertex2)
        {
            _ajacencyList[vertex1].Remove(vertex2);
            _ajacencyList[vertex2].Remove(vertex1);
            var con1 = new Edge <T>(vertex1, vertex2);
            var con2 = new Edge <T>(vertex2, vertex1);

            if (_edges.Contains(con1))
            {
                _edges.Remove(con1);
            }
            else if (_edges.Contains(con2))
            {
                _edges.Remove(con2);
            }
            var edges = _edges.ConvertAll(x => new Edge <T>(x.Vertex1, x.Vertex2));

            _ajacencyList         = new Dictionary <T, List <T> >();
            _edges                = new List <Edge <T> >();
            _dsuConnectivity      = new DSU <T>();
            _bridges              = new List <Edge <T> >();
            _dsu2EdgeConnectivity = new DSU <T>();
            foreach (var vertex in _vertices)
            {
                _ajacencyList.Add(vertex, new List <T>());
                _dsuConnectivity.MakeSet(vertex);
                _dsu2EdgeConnectivity.MakeSet(vertex);
            }
            foreach (var edge in edges)
            {
                AddEdge(edge.Vertex1, edge.Vertex2);
            }
        }
Esempio n. 2
0
 public DynamicConnectivityGraph(List <T> vertices)
 {
     _vertices             = vertices;
     _ajacencyList         = new Dictionary <T, List <T> >();
     _edges                = new List <Edge <T> >();
     _bridges              = new List <Edge <T> >();
     _dsuConnectivity      = new DSU <T>();
     _dsu2EdgeConnectivity = new DSU <T>();
     foreach (var vertex in vertices)
     {
         _ajacencyList.Add(vertex, new List <T>());
         _dsuConnectivity.MakeSet(vertex);
         _dsu2EdgeConnectivity.MakeSet(vertex);
     }
 }