#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; struct Way{ int to,cost; Way(){} Way(int _to,int _cost){ to=_to; cost=_cost; } }; struct Data{ int n,cost; Data(){} Data(int _n,int _cost){ n=_n; cost=_cost; } bool operator<(const Data &a)const{ return cost>a.cost; } }; int N,M,S,G,A,B,C; vector way[200]; int memo[200],d[200]; void dfs(int n,vector ans){ if(memo[n]==true) return; memo[n] = true; ans.push_back(n); if(n==G){ printf("%d",ans[0]); for(int i=1;i way_; for(int i=0;i>N>>M>>S>>G; for(int i=0;i>A>>B>>C; way[A].push_back(Way(B,C)); way[B].push_back(Way(A,C)); } priority_queue pq; pq.push(Data(S,0)); Data pq_c; fill_n((int*)d,200,INT_MAX); while(!pq.empty()){ pq_c = pq.top(); pq.pop(); if(d[pq_c.n]!=INT_MAX) continue; d[pq_c.n] = pq_c.cost; for(int i=0;i ans; dfs(S,ans); return 0; }