Converting trees to dags