Efficient algorithm for common spanning tree problem