結果
問題 | No.160 最短経路のうち辞書順最小 |
ユーザー |
![]() |
提出日時 | 2015-03-01 23:58:59 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,319 bytes |
コンパイル時間 | 1,030 ms |
コンパイル使用メモリ | 92,012 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-24 00:44:20 |
合計ジャッジ時間 | 1,870 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 8 WA * 18 |
ソースコード
#include<iostream>#include<cstdio>#include<algorithm>#include<climits>#include<string>#include<vector>#include<list>#include<map>#include<set>#include<cmath>#include<queue>#include<cstring>#include<stack>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 main(){vector<Way> way[200];int N,M,S,G,A,B,C;cin>>N>>M>>S>>G;for(int i=0;i<M;i++){cin>>A>>B>>C;way[A].push_back(Way(B,C)); way[B].push_back(Way(A,C));}priority_queue<Data> pq; pq.push(Data(S,0));Data pq_c;int d[200]; 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<way[pq_c.n].size();i++){pq.push(Data(way[pq_c.n][i].to,pq_c.cost+way[pq_c.n][i].cost));}}stack<int> s;int n=G;s.push(n);while(n!=S){int next=INT_MAX;for(int i=0;i<way[n].size();i++){if(d[n]-way[n][i].cost == d[way[n][i].to]){next = min(next,way[n][i].to);}}n = next;s.push(n);}printf("%d",s.top()); s.pop();while(!s.empty()){printf(" %d",s.top()); s.pop();}puts("");return 0;}