//intersections交叉,相交,十字路口 indices指数,编号,索引(index)
// source起点 In case如果,万一 identical完全相同的 format格式
//being the total number of streets intersections on a map, and the number of streets, respectively.
//分别为地图上的街道交叉口总数和街道数量。
//In case the shortest and the fastest paths are identical, print them in one line in the format:
//如果最短路径和最快路径相同,请按以下格式打印在一行中:
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
//找一个最短路和一个最快的路
//如果最短路线不唯一,则输出用时最短的那条路线(保证唯一)。
//如果最快路线不唯一,则输出经过路口最少的那条路线(保证唯一)。
//并记录路线方案
const int N = 510;
int n,m,S,T;
int d1[N][N],d2[N][N];
int dist1[N],dist2[N],pre[N];
bool st[N];
//返回值,距离和路线pair<int,string>
pair<int,string> dijkstra(int d1[][N],int d2[][N],int type)
{
memset(dist1,0x3f,sizeof dist1);
memset(dist2,0x3f,sizeof dist2);
memset(st,0,sizeof st);
dist1[S] = dist2[S] = 0;
for(int i = 0; i<n; i++)
{
int t = -1;
for(int j = 0; j<n; j++)
if(!st[j] &&(t==-1 || dist1[t] > dist1[j]))
t = j;
st[t] = true;
for(int j = 0; j<n; j++)
{
int w;
if(type == 0) w = d2[t][j];
else w = 1;
if(dist1[j] > dist1[t] + d1[t][j])
{
dist1[j] = dist1[t] + d1[t][j];
dist2[j] = dist2[t] + w;
pre[j] = t;
}
else if(dist1[j] == dist1[t] + d1[t][j])
{
if(dist2[j] > dist2[t] + w)
{
dist2[j] = dist2[t] + w;
pre[j] = t;
}
}
}
}
vector<int> path;
for(int i = T; i!=S; i = pre[i]) path.push_back(i);
pair<int,string> res;
res.first = dist1[T];
res.second = to_string(S);
for(int i = path.size()-1; i>=0; i--)
res.second += " -> "+to_string(path[i]);
return res;
}
int main()
{
cin>>n>>m;
memset(d1,0x3f,sizeof d1);
memset(d2,0x3f,sizeof d2);
while(m--)
{
int a,b,t,c,d;
cin>>a>>b>>t>>c>>d;
d1[a][b] = min(d1[a][b],c);
d2[a][b] = min(d2[a][b],d);
if(!t)//双行道
{
d1[b][a] = min(d1[b][a],c);
d2[b][a] = min(d2[b][a],d);
}
}
cin>>S>>T;
auto A = dijkstra(d1,d2,0);
auto B = dijkstra(d2,d1,1);
if(A.second != B.second)
{
printf("Distance = %d: %s\n",A.first,A.second.c_str());
printf("Time = %d: %s\n",B.first,B.second.c_str());
}
else printf("Distance = %d; Time = %d: %s\n",A.first,B.first,A.second.c_str());
return 0;
}