cpp-library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub 9tc/cpp-library

:x: 全点対最短経路(ワーシャルフロイド法)
(graph/warshall-floyd.hpp)

Verified with

Code

template<typename T>
vector<vector<T>> warshallFloyd(vector<vector<T>> mat, T infty){
  int n = mat.size();
  for(int k = 0; k < n; ++k){
    for(int i = 0; i < n; ++i){
      for(int j = 0; j < n; ++j){
        if(mat[i][k] == infty || mat[k][j] == infty) continue;
        mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
      }
    }
  }
  return mat;
}
#line 1 "graph/warshall-floyd.hpp"
template<typename T>
vector<vector<T>> warshallFloyd(vector<vector<T>> mat, T infty){
  int n = mat.size();
  for(int k = 0; k < n; ++k){
    for(int i = 0; i < n; ++i){
      for(int j = 0; j < n; ++j){
        if(mat[i][k] == infty || mat[k][j] == infty) continue;
        mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
      }
    }
  }
  return mat;
}
Back to top page