Directed graph, cycle detection and bfs / dfs