結果

問題 No.160 最短経路のうち辞書順最小
ユーザー latte0119latte0119
提出日時 2015-03-02 01:00:53
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 824 bytes
コンパイル時間 244 ms
コンパイル使用メモリ 42,652 KB
実行使用メモリ 4,568 KB
最終ジャッジ日時 2023-09-06 06:13:15
合計ジャッジ時間 1,616 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n,m,s,g;
int mat[300][300];
int flag[300][300];
int main(){
    scanf("%d%d%d%d",&n,&m,&s,&g);
    fill_n(*mat,300*300,1<<25);
    fill_n(*flag,300*300,0);
    for(int i=0;i<n;i++)mat[i][i]=0;
    while(m--){
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        mat[a][b]=mat[b][a]=c;
        flag[a][b]=flag[b][a]=1;
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                mat[i][j]=min(mat[i][j],mat[i][k]+mat[k][j]);
            }
        }
    }
    printf("%d",s);
    while(s!=g){
        for(int i=0;i<n;i++){
            if(mat[s][i]+mat[i][g]==mat[s][g]&&flag[s][i]){
                printf(" %d",s=i);
                break;
            }
        }
    }
    puts("");
}
0