Let a be the average size of an adjacency list Adj[u].
Let d be the current distance from S in the search.