let rec add x y t =
let dist n = match n with Node (x1,_,_) -> distance x x1 in
match select (order_by_asc dist) 1 t with
| ([Node (a,b,children)], other_roots) ->
if length children < max_degree
then Node (a, b, Node (x, y, []) :: children) :: other_roots
else Node (a, b, add x y children)::other_roots
| (_, _) -> [Node (x, y, [])]