#include #include #include #include #include const int INF = 1e9; struct Edge { int to, cost; bool operator>(const Edge &e) const { return this->to > e.to; } bool operator<(const Edge &e) const { return this->to < e.to; } }; class Vertex { public: int cost; int no; bool operator>(const Vertex &v) const { return this->cost > v.cost; } std::vector v_edge; }; int main() { int N; std::cin >> N; int M; std::cin >> M; int S; std::cin >> S; int G; std::cin >> G; std::vector v_vertex(N); for(int m=0; m> a; int b; std::cin >> b; int c; std::cin >> c; v_vertex[a].v_edge.push_back(Edge{b,c}); v_vertex[b].v_edge.push_back(Edge{a,c}); } for(auto &x : v_vertex) { // std::sort(x.v_edge.begin() , x.v_edge.end() , std::greater()); std::sort(x.v_edge.begin() , x.v_edge.end()); } for(int n=0; n , std::greater > q; q.push(v_vertex[S]); while(!q.empty()) { Vertex v = q.top(); q.pop(); if(v_vertex[v.no].cost < v.cost) continue; for(auto &x : v.v_edge) { if(v_vertex[x.to].cost > v.cost+x.cost) { v_vertex[x.to].cost = v.cost+x.cost; q.push(v_vertex[x.to]); } } } std::stack > st; std::vector tmp; tmp.push_back(G); st.push(tmp); std::vector > ans; while(!st.empty()) { std::vector current = st.top(); st.pop(); if(current[current.size()-1]==S) { ans.push_back(current); /* for(auto &x : current) */ /* { */ /* std::cout << x << " "; */ /* } */ /* std::cout << std::endl; */ break; } else { for(auto &x : v_vertex[current[current.size()-1]].v_edge) { if(v_vertex[x.to].cost+x.cost==v_vertex[current[current.size()-1]].cost) { std::vector tmp = current; tmp.push_back(x.to); st.push(tmp); break; } } } } std::vector Ans = *std::min_element(ans.begin() , ans.end()); std::reverse(Ans.begin() ,Ans.end()); for(int i=0; i