#include<iostream> #include<vector> using namespace std; void shortestPath(vector<vector<int> > &matrix,int n){ vector<int> final(n); vector<int> distance(n); int v; for (int i = 0; i < n; ++i){ final[i] = false; distance[i] = matrix[0][i]; } for (int j = 1; j < n; ++j){ int min = INT_MAX; for (int w = 0; w < n; ++w){ if (!final[w]) if (distance[w] < min){ v = w; min = distance[w]; } } final[v] = true; for (int i = 0; i < n; ++i){ if (!final[i] && (min + matrix[v][i] < distance[i])){ distance[i] = min + matrix[v][i]; } } } for (int i = 0; i < n; ++i){ cout << distance[i] << endl; } } int main() { int n; cout << "please input a number :" << endl; cin >> n; vector<vector<int> > matrix(n, vector<int>(n,0)); cout << "please input" << endl; for (int i = 0; i < n; ++i){ for (int j = 0; j < n; ++j){ cin>>matrix[i][j]; } } shortestPath(matrix,n); return 0; }