Esempio n. 1
0
 void
 initialize_dynamic_components(VertexListGraph& G,
                               DisjointSets& ds)
 {
   typename graph_traits<VertexListGraph>
     ::vertex_iterator v, vend;
   for (tie(v, vend) = vertices(G); v != vend; ++v)
     ds.make_set(*v);
 }
Esempio n. 2
0
    // If v does not exist, then add it to the disjoint set.
    void ensureElementExists(int v) const
    {
      elements_t::const_iterator it = elements_.find(v);
      if (it == elements_.end()) {
	disjoint_sets_.make_set(v);
	elements_.insert(v);
	
	std::list<int> li;
	li.push_front(v);
	rootSetMap_[v] = li;
      }
      return;
    }
	void __output_ancestors(Vertex from, Vertex const u, Vertex const v) {
		sets.make_set(from);
		ancestors[sets.find_set(from)] = from;
		VertexContainer child = children(from);
		for (VertexContainer::iterator ite = child.begin(); ite != child.end(); ++ite) {
			__output_ancestors(*ite, u, v);
			sets.union_set(from, *ite);
			ancestors[sets.find_set(from)] = from;
		}
		colors[from] = black;
		if (u == from && colors[v] == black) {
			printf("The least common ancestor of %d and %d is %d.\n",
				query_dat(u), query_dat(v), query_dat(ancestors[sets.find_set(v)]));
		}
		else if (v == from && colors[u] == black) {
			printf("The least common ancestor of %d and %d is %d.\n",
				query_dat(v), query_dat(u), query_dat(ancestors[sets.find_set(u)]));
		}
	}