#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include const double EPS = (1e-10); using namespace std; using Int = long long; //using namespace boost::multiprecision; const Int MOD = 1000000007; Int mod_pow(Int x, Int n) { Int res = 1; while(n > 0) { if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき) x = (x * x) % MOD; n >>= 1; //右シフト(n = n >> 1) } return res; } //最大公約数 template T gcd(T a, T b) { return b != 0 ? gcd(b, a % b) : a; } //最小公倍数 template T lcm(T a, T b) { return a * b / gcd(a, b); } struct Edge{ int from, to; Int cost; }; template vector dijkstra(vector> &G, int s) { int V = G.size(); vector d(V); fill(d.begin(), d.end(), numeric_limits::max()); priority_queue , vector< pair >, greater< pair > > que; d[s] = 0; que.push(make_pair(0,s)); while(!que.empty()) { pair p = que.top(); que.pop(); int v = p.second; if(d[v] < p.first) continue; for(int i=0; i d[v] + e.cost) { d[e.to] = d[v] + e.cost; que.push(make_pair(d[e.to], e.to)); } } } return d; } int main(){ cin.tie(0); int N, M; cin >> N >> M; vector> G(N*2+1); for (int i = 0; i < M; i++){ int a, b; Int c; cin >> a >> b >> c; Edge e = {a, b, c}; Edge e2 = {b, a, c}; Edge e3 = {a+N, b+N, c}; Edge e4 = {b+N, a+N, c}; Edge e5 = {a, b+N, 0}; G[a].push_back(e); G[b].push_back(e2); G[a+N].push_back(e3); G[b+N].push_back(e4); G[a].push_back(e5); } vector d = dijkstra(G, 1); for (int i = 1; i <= N; i++){ if (i == 1) cout << 0 << endl; else cout << d[i] + d[i+N] << endl; } return 0; }