結果

問題 No.160 最短経路のうち辞書順最小
ユーザー latte0119latte0119
提出日時 2015-03-01 23:58:18
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,422 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 65,480 KB
実行使用メモリ 813,820 KB
最終ジャッジ日時 2023-09-06 06:03:03
合計ジャッジ時間 5,873 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 5 ms
4,376 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<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
struct edge{int to,cost;};
struct data{
    int pos,cost;
    bool operator>(const data &d)const{
        return cost>d.cost;
    }
};
const int INF=1e9+7;
int n,m,s,g;
vector<edge>G[200];
int d[200];
set<vector<int> >S;
void dfs(int pos,int cost,vector<int>way){
    way.push_back(pos);
    if(pos==s){
        reverse(way.begin(),way.end());
        S.insert(way);
        return;
    }
    for(int i=0;i<G[pos].size();i++){
        edge &e=G[pos][i];
        if(d[e.to]==cost-e.cost){
            dfs(e.to,cost-e.cost,way);
        }
    }
}
int main(){
    scanf("%d%d%d%d",&n,&m,&s,&g);
    for(int i=0;i<m;i++){
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        G[a].push_back((edge){b,c});
        G[b].push_back((edge){a,c});
    }
    fill_n(d,n,INF);
    priority_queue<data,vector<data>,greater<data> >Q;
    Q.push((data){s,0});
    while(Q.size()){
        int pos=Q.top().pos,cost=Q.top().cost;
        Q.pop();
        if(d[pos]<cost)continue;
        d[pos]=cost;
        for(int i=0;i<G[pos].size();i++){
            edge &e=G[pos][i];
            Q.push((data){e.to,cost+e.cost});
        }
    }
    dfs(g,d[g],vector<int>(0));
    vector<int>ans=*(S.begin());
    for(int i=0;i<ans.size();i++){
        if(i)printf(" ");
        printf("%d",ans[i]);
    }
    puts("");
    return 0;
}
0