1 #include <set>
2 #include <map>
3 #include <list>
4 #include <cmath>
5 #include <ctime>
6 #include <deque>
7 #include <queue>
8 #include <stack>
9 #include <cstdio>
10 #include <string>
11 #include <vector>
12 #include <cctype>
13 #include <cstring>
14 #include <sstream>
15 #include <fstream>
16 #include <cstdlib>
17 #include <cassert>
18 #include <iostream>
19 #include <algorithm>
20
21 using namespace std;
22 //Constant Declaration
23 /*--------------------------*/
24 //#define LL long long
25 #define LL __int64
26 const int M=1100;//最多点数
27 const int INF=1<<30;
28 const double EPS = 1e-11;
29 const double PI = acos(-1.0);
30 /*--------------------------*/
31 // some essential funtion
32 /*----------------------------------*/
33 void Swap(int &a,int &b){ int t=a;a=b;b=t; }
34 int Max(int a,int b){ return a>b?a:b; }
35 int Min(int a,int b){ return a<b?a:b; }
36 int Gcd(int a,int b){ while(b){b ^= a ^=b ^= a %= b;} return a; }
37 /*----------------------------------*/
38 //for (i = 0; i < n; i++)
39 /*----------------------------------*/
40
41 struct djs
42 {
43 int l,p;
44 }d[M],g[M][M];
45
46 bool used[M];
47 void init(int n)
48 {
49 int i, j;
50 for (i = 1; i <= n; i++)
51 {
52 for (j = 1; j <= n; j++)
53 {
54 g[i][j].l = INF;
55 g[i][j].p = INF;
56 }
57 }
58 for (i = 1; i <= n; i++)
59 {
60 d[i].l = INF;
61 d[i].p = INF;
62 }
63
64 memset(used, 0, sizeof(used));
65 }
66
67
68
69 int dijkstra(int star, int end, int n)
70 {
71 int min_num;
72 int i;
73 d[star].l= 0;
74 d[star].p= 0;
75 for (int cnt = 0; cnt < n; cnt++)
76 {
77 int min = INF;
78 for (i = 1; i <= n; i++)
79 {
80 if (!used[i] && d[i].l < min)
81 {
82 min = d[i].l;
83 min_num = i;
84 }
85 }
86
87 used[min_num] = 1;
88
89 for (i = 1; i <= n; i++)
90 {
91 if (!used[i] && d[i].l > d[min_num].l + g[min_num][i].l)
92 {
93 d[i].l = d[min_num].l + g[min_num][i].l;
94 d[i].p = d[min_num].p + g[min_num][i].p;
95 }
96 if (!used[i] && d[i].l == d[min_num].l + g[min_num][i].l && d[i].p > d[min_num].p + g[min_num][i].p)
97 {
98 d[i].p = d[min_num].p + g[min_num][i].p;
99 }
100 }
101
102 }
103 return d[end].l;
104 }
105
106
107
108
109
110 int main()
111 {
112
113 int n, m;
114 int i, j;
115 while (scanf("%d%d", &n, &m), n + m)
116 {
117 init(n);
118 for (i = 0; i < m; i++)
119 {
120 int a, b, c, c1;
121 scanf("%d%d%d%d", &a, &b, &c, &c1);
122 if (g[a][b].l > c)
123 {
124 g[b][a].l = g[a][b].l = c;
125 g[b][a].p= g[a][b].p = c1;
126 }
127 if (g[a][b].l == c && g[b][a].p > c1)
128 {
129 g[b][a].p= g[a][b].p = c1;
130 }
131
132 }
133 int star, end,ans;
134 scanf("%d%d", &star, &end);
135 ans = dijkstra(star, end, n);
136 printf("%d %d\n", ans, d[end].p);
137 }
138
139 return 0;
140 }