Spanning tree solution created and basically tested. Solution fails with memory limit exceeded.