#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; long long v[100010][2]; vector>> vec(100010); long long inf = 1000000000000007; int main() { long long n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 0; j < 2; j++) { v[i][j] = inf; } } for (int i = 0; i < m; i++) { long long a, b, c, x; cin >> a >> b >> c >> x; vec[a].emplace_back(make_tuple(b, c, x)); vec[b].emplace_back(make_tuple(a, c, x)); } v[n][0] = 0; priority_queue,vector>,greater>> que; que.push(make_tuple(0, n, 0)); while (!que.empty()) { tuple t = que.top(); long long y = get<0>(t); long long x = get<1>(t); int z = get<2>(t); que.pop(); if (v[x][z] < y) { continue; } for (int i = 0; i < vec[x].size(); i++) { tuple t1 = vec[x][i]; long long x1 = get<0>(t1); long long y1 = get<1>(t1); int z1 = get<2>(t1); if (v[x1][z|z1] > y + y1) { v[x1][z|z1] = y + y1; que.push(make_tuple(v[x1][z|z1], x1, z1)); } } } for (int i = 1; i < n; i++) { cout << v[i][1] << endl; } }