結果
| 問題 | No.17 2つの地点に泊まりたい | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2016-08-27 23:21:55 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                CE
                                 
                            (最新) 
                                AC
                                 
                            (最初) | 
| 実行時間 | - | 
| コード長 | 1,366 bytes | 
| コンパイル時間 | 1,246 ms | 
| コンパイル使用メモリ | 135,300 KB | 
| 最終ジャッジ日時 | 2024-11-14 19:48:45 | 
| 合計ジャッジ時間 | 1,647 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
            
            
            
            
            ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
Main.d(38): Error: incompatible types for `(r1) + (r2)`: both operands are of type `Nullable!int` Main.d(58): Error: incompatible types for `(d1) + (d2)`: both operands are of type `Nullable!int` Main.d(60): Error: incompatible types for `(d1) + (d2)`: both operands are of type `Nullable!int`
ソースコード
import std.algorithm, std.array, std.container, std.range;
import std.string, std.conv, std.math;
import std.stdio, std.typecons;
alias Tuple!(int, "v", int, "c") side;
void main()
{
  auto n = readln.chomp.to!int;
  auto sti = iota(n).map!(i => readln.chomp.to!int).array;
  auto graph = new Nullable!int[][n];
  foreach (ref l; graph)
    l = new Nullable!int[n];
  foreach (i; 0..n)
    graph[i][i] = 0;
  auto m = readln.chomp.to!int;
  foreach (i; 0..m) {
    auto rd = readln.split.map!(to!int);
    graph[rd[0]][rd[1]] = rd[2];
    graph[rd[1]][rd[0]] = rd[2];
  }
  warshal_floyd(graph);
  auto min = int.max;
  foreach (s1; 1..(n - 1)) {
    foreach (s2; 1..(n - 1)) {
      if (s1 == s2)
        continue;
      auto r1 = graph[0][s1];
      auto r2 = graph[s1][s2];
      auto r3 = graph[s2][n - 1];
      if (!r1.isNull && !r2.isNull && !r3.isNull) {
        auto r = r1 + r2 + r3 + sti[s1] + sti[s2];
        if (r < min)
          min = r;
      }
    }
  }
  writeln(min);
}
void warshal_floyd(Nullable!int[][] d)
{
  auto n = d.length;
  foreach (k; 0..n)
    foreach (i; 0..n)
      foreach (j; 0..n) {
        auto d1 = d[i][k];
        auto d2 = d[k][j];
        if (!d1.isNull && !d2.isNull) {
          if (!d[i][j].isNull)
            d[i][j] = min(d[i][j], d1 + d2);
          else
            d[i][j] = d1 + d2;
        }
      }
}
            
            
            
        