#include typedef struct List { struct List *next; int v, cost, x; } list; void chmin(long long* a, long long b) { if (*a > b) *a = b; } void naive(int N, list* adj[], int s, long long ans[]) { int i, j, k, u, w; const long long sup = 1LL << 60; long long dist[1001][1001]; list *p; for (u = 1; u <= N; u++) for (w = 1; w <= N; w++) dist[u][w] = (u == w)? 0: sup; for (u = 1; u <= N; u++) for (p = adj[u]; p != NULL; p = p->next) chmin(&(dist[u][p->v]), p->cost); for (k = 1; k <= N; k++) { for (i = 1; i <= N; i++) { for (j = 1; j <= N; j++) { if (dist[i][k] == sup || dist[k][j] == sup) continue; chmin(&(dist[i][j]), dist[i][k] + dist[k][j]); } } } int t; for (u = 1; u < N; u++) ans[u] = sup; for (u = 1; u <= N; u++) { for (p = adj[u]; p != NULL; p = p->next) { if (p->x == 0) continue; w = p->v; for (t = 1; t <= N; t++) chmin(&(ans[t]), dist[t][u] + dist[w][s] + p->cost); } } } int main() { int i, N, M, u, w, c, x; list *adj[1001] = {}, e[10001]; scanf("%d %d", &N, &M); if (N > 1000) return 0; for (i = 0; i < M; i++) { scanf("%d %d %d %d", &u, &w, &c, &x); e[i*2].v = w; e[i*2+1].v = u; e[i*2].cost = c; e[i*2+1].cost = c; e[i*2].x = x; e[i*2+1].x = x; e[i*2].next = adj[u]; e[i*2+1].next = adj[w]; adj[u] = &(e[i*2]); adj[w] = &(e[i*2+1]); } long long ans[1001]; naive(N, adj, N, ans); for (u = 1; u < N; u++) printf("%lld\n", ans[u]); fflush(stdout); return 0; }