1 #include <iostream> 2 3 using namespace std; 4 5 int n, m; 6 int minn; 7 int u; 8 int dis[100010], book[100010], t1, t2, t3, e[10010][10010]; 9 10 int main(){ 11 cin >> n >> m; 12 for(int i = 1; i <= n; i++) 13 for(int j = 1; j <= n; j ++) 14 if(i == j) e[i][j] = 0; 15 else e[i][j] = 999999999; 16 for(int i = 1; i <= m; i ++){ 17 cin >> t1 >> t2 >> t3; 18 e[t1][t2] = t3; 19 } 20 for(int i = 1; i <= n; i ++) dis[i] = e[1][i]; 21 for(int i = 1; i <= n; i ++) book[i] = 0; 22 book[1] = 1; 23 for(int i = 1; i <= n; i ++){ 24 minn = 999999999; 25 for(int j = 1; j <= n; j ++){ 26 if(book[j] == 0 && dis[j] < minn){ 27 minn = dis[j]; 28 u = j; 29 } 30 } 31 book[u] = 1; 32 for(int j = 1; j <= n; j ++){ 33 if(e[u][j] < 999999999){ 34 if(dis[j] > dis[u] + e[u][j]) dis[j] = dis[u] + e[u][j]; 35 } 36 } 37 } 38 for(int i = 1; i <= n; i ++) cout << dis[i]; 39 return 0; 40 }