implement spanning_tree