結果

問題 No.160 最短経路のうち辞書順最小
ユーザー ikdikd
提出日時 2017-11-15 12:48:21
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 861 bytes
コンパイル時間 2,125 ms
コンパイル使用メモリ 140,600 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 16:55:14
合計ジャッジ時間 4,318 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n, m, s, g; rd(n, m, s, g);
  auto d=new int[][](n, n);
  const inf=1_000_000_000;
  foreach(i; 0..n) fill(d[i], inf), d[i][i]=0;
  auto es=new int[][](n, n);
  foreach(i; 0..m){
    int a, b, c; rd(a, b, c);
    d[a][b]=d[b][a]=c;
    es[a][b]=es[b][a]=c;
  }

  foreach(_; 0..n)foreach(i; 0..n)foreach(j; 0..n){
    d[i][j]=min(d[i][j], d[i][_]+d[_][j]);
  }
  auto mn=d[s][g], r=new int[](0);
  for(auto cur=s; cur!=g; ){
    r~=cur;
    foreach(nex; 0..n){
      if(es[cur][nex] && d[cur][g]==d[nex][g]+es[cur][nex]){
        cur=nex;
        break;
      }
    }
  }
  r~=g;
  writefln("%(%d %)", r);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
0