結果
問題 | No.160 最短経路のうち辞書順最小 |
ユーザー | IL_msta |
提出日時 | 2015-08-09 23:23:00 |
言語 | C++11 (gcc 11.4.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 3,310 bytes |
コンパイル時間 | 1,014 ms |
コンパイル使用メモリ | 101,660 KB |
実行使用メモリ | 823,884 KB |
最終ジャッジ日時 | 2024-07-18 06:23:36 |
合計ジャッジ時間 | 7,497 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 10 ms
6,944 KB |
testcase_05 | AC | 22 ms
6,940 KB |
testcase_06 | AC | 38 ms
6,940 KB |
testcase_07 | MLE | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
ソースコード
#define _USE_MATH_DEFINES #include <iostream> #include <iomanip> #include <sstream> #include <algorithm> #include <cmath> #include <string> //#include <array> #include <list> #include <queue> #include <vector> #include <complex> #include <set> #include <map> ///////// #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)<<endl; #define PII pair<int,int> ///////// 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<int>,vector<vector<int>>,greater<vector<int>>> q; vector<int> itq; bool use[Vmax]; PII dist[Vmax];//cost,prev rep(i,N){ use[i] = false; dist[i] = PII( -1,-1); } vector<int> vec(3); vec[0] = 0; vec[1] = start; vec[2] = start; //cost,prev,now q.push( vec ); vector<int> 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<int>::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<N ;++i){//頂点数 //if( use[i] == true || vvc[ itq[2] ][i] < 0 ) continue; if( vvc[ itq[2] ][i] < 0 ) continue; vec[0] = itq[0] + vvc[ itq[2] ][i]; vec[1] = itq[2]; vec[2] = i; if( use[i] == true && dist[ vec[2] ].first < vec[0] ) continue; q.push( vec ); } } int path[Vmax]; int pathCount = 0; int pathPrev = goal; while( pathPrev != start ) { path[pathCount] = pathPrev; ++pathCount;; pathPrev = dist[pathPrev].second; } path[pathCount] = start; while(pathCount > 0){ cout << path[pathCount] << " "; --pathCount; } cout << path[pathCount] << endl; return 0; }