queue solved, loop in karp