BELLMEN-FORD普通
#include <iostream>
using namespace std;
int m, n, u[100010], v[100010], w[100010];
int check;
int dis[100010];
int main(){
cin >> n >> m;
for(int i = 1; i <= m; i ++) cin >> u[i] >> v[i] >> w[i];
for(int i = 1; i <= n; i ++) dis[i] = 999999999;
dis[1] = 0;
for(int i = 1; i <= n - 1; i ++){
check = 0;
for(int j = 1; j <= m; j ++){
if(dis[v[j]] > dis[u[j]] + w[j]){
dis[v[j]] = dis[u[j]] + w[j];
check = 1;
}
}
if(check == 0) break;
}
for(int i = 1; i <= n; i ++) cout << dis[i] << " " ;
return 0;
}