function doDfs(G[n]: Graph):
visited = array[n, false]
function DFS(u: int):
visited[u] = true
for v: (u, v) in G:
if not visited[v]:
DFS(v)
for i = 1 to n:
if not visited[i]:
DFS(i)