#include #include #include #include #include int main() { int n, m, s, g; int t1, t2, t3; int i, j, k; bool b; std::string str; int cost[256][256] = {}; int next[256][256] = {}; std::cin >> n >> m >> s >> g; for(i = 0; i < n; i++) { for(j = 0; j < n; j++) { next[i][j] = -1; cost[i][j] = -1; } } for(i = 0; i < m; i++) { std::cin >> t1 >> t2 >> t3; cost[t1][t2] = t3; next[t1][t2] = t2; cost[t2][t1] = t3; next[t2][t1] = t1; } for(;;) { b = true; for(i = 0; i < n; i++) { for(j = 0; j < n; j++) { if(i == j) { continue; } for(k = 0; k < n; k++) { if(i == k) { continue; } if(j == k) { continue; } if( cost[i][k] != -1 && cost[k][j] != -1 ) { if( cost[i][j] == -1 || cost[i][j] > cost[i][k] + cost[k][j] ) { b = false; next[i][j] = k; cost[i][j] = cost[i][k] + cost[k][j]; continue; } if( cost[i][j] == cost[i][k] + cost[k][j] ) { if( next[i][j] > k ) { b = false; next[i][j] = k; cost[i][j] = cost[i][k] + cost[k][j]; } } } } } } if( b ) { break; } } t1 = s; printf("%d", t1); for(;;) { t2 = next[t1][g]; for(;;) { if( t2 == next[t1][t2] ) { break; } t2 = next[t1][t2]; } t1 = t2; printf(" %d", t1); if(t1 == g) { break; } } printf("\n"); return 0; }