#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define INF_MIN 100000000 #define INF 1145141919 #define INF_MAX 2147483647 #define LL_MAX 9223372036854775807 #define EPS 1e-10 #define PI acos(-1) #define LL long long using namespace std; #define MAX_N 201 #define MAX_M 40001 typedef pair P; //distance, next int N, M, S, G; vector

Edge[MAX_N]; int dp[MAX_N]; int dpList[MAX_N]; void solve(){ priority_queue, greater

> que; fill(dp, dp+N, INF); fill(dpList, dpList+N, INF); dp[S] = 0; que.push(P(0, S)); while(que.size()){ P p = que.top(); que.pop(); int dis = p.first; int pos = p.second; if(dp[pos] < dis) continue; for(int i = 0; i < Edge[pos].size(); i++){ int nextPos = Edge[pos][i].second; int nextDis = Edge[pos][i].first; if(dp[nextPos] > dis + nextDis){ dp[nextPos] = dis + nextDis; que.push(P(dp[nextPos], nextPos)); dpList[nextPos] = pos; } else if(dp[nextPos] == dis + nextDis){ if(dpList[nextPos] < pos) continue; que.push(P(dp[nextPos], nextPos)); dpList[nextPos] = pos; } } } } int main(){ cin >> N >> M >> S >> G; for(int i = 0; i < M; i++){ int a, b, c; cin >> a >> b >> c; Edge[a].push_back(P(c, b)); Edge[b].push_back(P(c, a)); } solve(); vector ans; ans.push_back(G); int pos = dpList[G]; while(true){ ans.push_back(pos); if(pos == S) break; pos = dpList[pos]; } reverse(ans.begin(), ans.end()); for(int i = 0; i < ans.size(); i++){ cout << ans[i]; if(i < ans.size() - 1) cout << " "; } cout << endl; return 0; }