Floyd's algorithm

Maybe.