added code for spanningTree