added spanning tree generation code