Floyd's algorithm exercise