let rec remove_cycles2 tree cycle n=
  let _ = report2 ("n="^(string_of_int n))
  in let back_edges = backward_edges tree
  in let _ = report2 ("tagasiulatuvaid servi "^(string_of_int (List.length back_edges)))
  in if n==0
  then Left (graph_from_tree tree)
  else 
    match cycle with
      x::t -> let _ = report2 (String.concat "\n" ("valitud"::(List.map (fun x -> String.concat "<-" (List.map (node_to_string_id tree) x)) ([cycle]))))
              in let (tr,cyc) = choose_move cycle tree
              in remove_cycles2 tr cyc (n-1)
    | _ -> (match (find_cycles tree) with
              c::tail -> let next_cyc = (find_next_cycle (c::tail) tree)
                      in let _ = report2 (String.concat "\n" ("uus tsykkel"::(List.map (fun x -> String.concat "<-" (List.map (node_to_string_id tree) x)) ([next_cyc]))))
                      in let (tr,cyc) = choose_move next_cyc (rearrange tree (List.hd (List.rev next_cyc)) next_cyc)
                      in remove_cycles2 tr cyc (n-1)
            | _ -> let _ = report2 "+++THE END+++"
                   in Left (graph_from_tree tree))