結果

問題 No.160 最短経路のうち辞書順最小
ユーザー goodbatongoodbaton
提出日時 2015-03-02 00:56:44
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,601 bytes
コンパイル時間 1,735 ms
コンパイル使用メモリ 84,700 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 06:13:08
合計ジャッジ時間 2,031 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 5 ms
4,376 KB
testcase_06 AC 5 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 2 ms
4,376 KB
testcase_28 WA -
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;


int main(){
    int n,m,s,g,a,b,c,cost[200];
    vector<pair<int,int> > way[200];
    vector<int> ans[200];
    priority_queue<pair<int,pair<int,int> > > pq;
    vector<int> vec;
    
    scanf("%d%d%d%d",&n,&m,&s,&g);
    
    for(int i=0;i<n;i++)
        cost[i]=-1000000000;
    
    for(int i=0;i<m;i++){
        scanf("%d%d%d",&a,&b,&c);
        
        way[a].push_back(make_pair(b,c));
        way[b].push_back(make_pair(a,c));
    }
    
    cost[s]=0;
    for(int i=0;i<way[s].size();i++){
        pq.push(make_pair(-way[s][i].second,make_pair(-s,way[s][i].first)));
    }
    
    
    while(1){
        pair<int,pair<int,int> > p = pq.top();
        pq.pop();
        
        if(cost[p.second.second]>=p.first) continue;
        
        
        ans[p.second.second]=ans[-p.second.first];
        ans[p.second.second].push_back(-p.second.first);
        cost[p.second.second]=p.first;
        
        
        if(p.second.second==g){
            
            for(int i=0;i<ans[g].size();i++){
                printf("%d ",ans[g][i]);
            }
            
            printf("%d\n",g);
            break;
        }
        
        for(int i=0;i<way[p.second.second].size();i++){
            pq.push(make_pair(p.first-way[p.second.second][i].second,
                              make_pair(-p.second.second,way[p.second.second][i].first)));
        }
    }
    
    return 0;
}
0