#include #define rep(i,n) for(int i=(0);i<(n);i++) using namespace std; typedef long long ll; template bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } struct edge {ll to, cost;}; typedef pair P; // firstはsからの最短距離, secondは頂点の番号 struct dat{ // sからの最短距離, 今の頂点の番号 ll dis, idx; bool operator<(const dat & a) const{ return dis > a.dis; } }; const ll INF = 1e17; const int max_n = 202020; int n; vector g[max_n]; void dijkstra(ll s, vector &d){ rep(i, 2 * n) d[i] = INF; d[s] = 0; d[s + n] = 0; priority_queue que; que.push({0, s}); while(!que.empty()){ dat p = que.top(); que.pop(); ll v = p.idx; if(d[v] < p.dis) continue; //後から最短パスが見つかった場合、先にqueに入っているものはここではじかれる for(ll i = 0; i < g[v].size(); i++){ edge e= g[v][i]; if(d[e.to] > d[v] + e.cost){ d[e.to] = d[v] + e.cost; que.push({d[e.to], e.to}); } } } } int main(){ cin.tie(0); ios::sync_with_stdio(false); int m; cin >> n >> m; rep(i, m){ ll a, b, c; cin >> a >> b >> c; a--; b--; g[a].push_back({b, c}); g[a].push_back({b+n, 0}); g[a+n].push_back({b+n, c}); g[b].push_back({a, c}); g[b].push_back({a+n, 0}); g[b+n].push_back({a+n, c}); } vector d(2 * n); dijkstra(0, d); rep(i, n) cout << d[i] + d[i+n] << endl; }