#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
const int inf = (1 << 31) - 10;
const int maxn = 550;
int N, M, S, D;
int cost[maxn][maxn], Time[maxn][maxn];
int used[maxn], d[maxn], w[maxn];
int pre1[maxn], pre2[maxn], sect[maxn];
void dijkstra1(int s){
memset(used, 0, sizeof(used));
fill(d, d + maxn, inf);
fill(w, w + maxn, inf);
d[s] = 0;
w[s] = 0;
for(int i = 0; i < N; i++){
int u = -1, Min = inf;
for(int v = 0; v < N; v++){
if(used[v] == 0 && d[v] < Min){
u = v;
Min = d[v];
}
}
used[u] = 1;
for(int v = 0; v < N; v++){
if(used[v] == 0 && cost[u][v] != inf){
if(d[v] > d[u] + cost[u][v]){
d[v] = d[u] + cost[u][v];
w[v] = w[u] + Time[u][v];
pre1[v] = u;
}else if(d[v] == d[u] + cost[u][v] && w[v] > w[u] + Time[u][v]){
w[v] = w[u] + Time[u][v];
pre1[v] = u;
}
}
}
}
}
void dijkstra2(int s){
memset(used, 0, sizeof(used));
fill(w, w + maxn, inf);
fill(sect, sect + maxn, inf);
w[s] = 0;
sect[s] = 1;
for(int i = 0; i < N; i++){
int u = -1, Min = inf;
for(int v = 0; v < N; v++){
if(used[v] == 0 && w[v] < Min){
u = v;
Min = w[v];
}
}
used[u] = 1;
for(int v = 0; v < N; v++){
if(used[v] == 0 && Time[u][v] != inf){
if(w[v] > w[u] + Time[u][v]){
w[v] = w[u] + Time[u][v];
pre2[v] = u;
sect[v] = sect[u] + 1;
}else if(w[v] == w[u] + Time[u][v] && sect[v] > sect[u] + 1){
pre2[v] = u;
sect[v] = sect[u] + 1;
}
}
}
}
}
void getPath(int x, int pre[]){
if(x == S){
printf("%d", S);
return;
}
getPath(pre[x], pre);
printf(" -> %d", x);
}
int isSame(int pre1[], int pre2[]){
int x, y;
x = y = D;
while(x != S || y != S){
if(x != y) return 0;
x = pre1[x];
y = pre2[y];
}
return 1;
}
void solve(){
dijkstra1(S);
dijkstra2(S);
pre1[S] = pre2[S] = S;
if(isSame(pre1, pre2)){
printf("Distance = %d; Time = %d: ", d[D], w[D]);
getPath(D, pre1); putchar('\n');
}else{
printf("Distance = %d: ", d[D]);
getPath(D, pre1); putchar('\n');
printf("Time = %d: ", w[D]);
getPath(D, pre2); putchar('\n');
}
}
int main(){
fill(cost[0], cost[0] + maxn * maxn, inf);
fill(Time[0], Time[0] + maxn * maxn, inf);
scanf("%d %d", &N, &M);
int v1, v2, f, w1, w2;
for(int i = 0; i < M; i++){
scanf("%d %d %d %d %d", &v1, &v2, &f, &w1, &w2);
cost[v1][v2] = w1;
Time[v1][v2] = w2;
if(f == 0){
cost[v2][v1] = w1;
Time[v2][v1] = w2;
}
}
scanf("%d %d", &S, &D);
solve();
return 0;
}