#define _USE_MATH_DEFINES #include #include #include #include #include #include //#include #include #include #include #include #include #include ///////// #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i,n) REP(i,0,n) #define P(p) cout<<(p)< ///////// typedef long long LL; typedef long double LD; ///////// using namespace::std; ///////// const int Vmax = 200; int main(void){ std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed;// //cout << setprecision(16);// int N,M,start,goal; cin>>N>>M>>start>>goal; int vvc[Vmax][Vmax]; rep(i,200)rep(j,200)vvc[i][j] = -1; int a,b,c; rep(i,M){ cin>>a>>b>>c; vvc[a][b] = c; vvc[b][a] = c; } //(cost,pos) priority_queue,vector>,greater>> q; vector itq; bool use[Vmax]; PII dist[Vmax];//cost,prev rep(i,N){ use[i] = false; dist[i] = PII( -1,-1); } vector vec(3); vec[0] = 0; vec[1] = start; vec[2] = start; //cost,prev,now q.push( vec ); vector path1(Vmax),path2(Vmax); while( !q.empty() ){ itq = q.top();q.pop(); if( use[ itq[2] ] == true ){ if( dist[ itq[2] ].first == itq[0]){ path1.clear(); path2.clear(); int point; //itq[1] path1.push_back(itq[2]); path1.push_back(itq[1]); point = dist[ itq[1] ].second; while( point != start ){ path1.push_back( point ); point = dist[ point ].second; } path1.push_back(start); /// path2.push_back( itq[2] ); point = dist[ itq[2] ].second; while( point != start ){ path2.push_back( point ); point = dist[ point ].second; } path2.push_back( start ); //reverse( path1.begin(),path1.end() ); //reverse( path2.begin(),path2.end() ); vector::reverse_iterator it1,it2; it1 = path1.rbegin(); it2 = path2.rbegin(); int pathCheck = -1; { int pathCount = 0; while( it1 != path1.rend() && it2 != path2.rend() ){ if( *it1 > *it2 ){ pathCheck = 2; break; }else if( *it1 < *it2 ){ pathCheck = 1; break; }else{ ++pathCount; } ++it1; ++it2; } if( pathCheck == -1){ if( path1.size() < path2.size() ){ pathCheck = 1; }else if( path1.size() < path2.size() ){ pathCheck = 2; } } } if( pathCheck == 1 ){ dist[ itq[2] ] = PII( itq[0],itq[1]); }else{ continue; } } }else{ use[ itq[2] ] = true; dist[ itq[2] ] = PII( itq[0],itq[1]); } for(int i=0; i 0){ cout << path[pathCount] << " "; --pathCount; } cout << path[pathCount] << endl; return 0; }