#include using namespace std; typedef long long ll; typedef pair l_l; #define EPS (1e-7) #define INF (1e18) #define PI (acos(-1)) //const ll mod = 1000000007; ll dist[100500][2]; vector pathes[100500]; int main() { //cout.precision(10); cin.tie(0); ios::sync_with_stdio(false); ll N, M; cin >> N >> M; for(int i = 1; i <= M; i++) { ll a, b, c; cin >> a >> b >> c; pathes[a].push_back({b, c}); pathes[b].push_back({a, c}); } priority_queue, greater > que; for(int i = 1; i <= N; i++) { for(int j = 0; j <= 1; j++) dist[i][j] = INF; } que.push({0, 1}); que.push({0, 200001}); while(!que.empty()) { l_l now = que.top(); que.pop(); int pos = now.second % (200000); int index = now.second / 200000; ll cost = now.first; if(dist[pos][index] <= cost) continue; dist[pos][index] = cost; for(int i = 0; i < pathes[pos].size(); i++) { l_l to = pathes[pos][i]; que.push({cost + to.second, to.first + index * 200000}); if(index == 0) { que.push({cost, to.first + 200000}); } } } for(int i = 1; i <= N; i++) { cout << dist[i][0] + dist[i][1] << endl; } return 0; }