結果

問題 No.160 最短経路のうち辞書順最小
ユーザー goodbatongoodbaton
提出日時 2015-03-02 00:39:47
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,541 bytes
コンパイル時間 1,180 ms
コンパイル使用メモリ 88,320 KB
実行使用メモリ 813,504 KB
最終ジャッジ日時 2023-09-06 06:11:37
合計ジャッジ時間 5,417 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 6 ms
4,504 KB
testcase_06 AC 7 ms
4,376 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 -- -
権限があれば一括ダウンロードができます

ソースコード

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];
    priority_queue<pair<int,pair<vector<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));
    }
    vec.push_back(-s);
    
    cost[s]=0;
    for(int i=0;i<way[s].size();i++){
        pq.push(make_pair(-way[s][i].second,make_pair(vec,way[s][i].first)));
    }
    
    
    while(1){
        pair<int,pair<vector<int>,int> > p = pq.top();
        pq.pop();
        
        if(p.second.second==g){
            
            for(int i=0;i<p.second.first.size();i++){
                printf("%d ",-p.second.first[i]);
            }
            
            printf("%d\n",g);
            break;
        }
        
        if(cost[p.second.second]>p.first) continue;
        
        cost[p.second.second]=p.first;
        
        vec = p.second.first;
        vec.push_back(-p.second.second);
        
        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(vec,way[p.second.second][i].first)));
        }
    }
    
    return 0;
}
0