Add the appropriate surrounding loop to your favorite graph traversal algorithm.