Algorithm described in my Graph Theory class