dfs_treeM: graph -> tree (with state) using State monad