is_valid_dag function

Checks whether a DAG is valid (no loops)