結果
| 問題 | No.17 2つの地点に泊まりたい | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2025-05-31 22:44:27 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 882 bytes | 
| コンパイル時間 | 2,517 ms | 
| コンパイル使用メモリ | 197,424 KB | 
| 実行使用メモリ | 7,844 KB | 
| 最終ジャッジ日時 | 2025-05-31 22:44:31 | 
| 合計ジャッジ時間 | 4,009 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 27 | 
ソースコード
module main;
// https://yang33-kassa.jp/yukicoder/yukicoder017/ より
import std;
void main()
{
	// 入力
	int N = readln.chomp.to!int;
	auto S = new long[](N);
	foreach (ref s; S)
		s = readln.chomp.to!long;
	int M = readln.chomp.to!int;
	immutable INF = 10L ^^ 16;
	auto dist = new long[][](N, N);
	foreach (ref row; dist)
		row[] = INF;
	foreach (i; 0 .. N)
		dist[i][i] = 0;
	foreach (_; 0 .. M) {
		long a, b, c;
		readln.chomp.formattedRead("%d %d %d", a, b, c);
		dist[a][b] = dist[b][a] = c;
	}
	// 答えの計算
	// ワーシャルフロイド法
	foreach (k; 0 .. N)
		foreach (i; 0 .. N)
			foreach (j; 0 .. N)
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
	long ans = INF;
	foreach (i; 1 .. N - 1)
		foreach (j; 1 .. N - 1)
			if (i != j)
				ans = min(ans, dist[0][i] + dist[i][j] + dist[j][N - 1] + S[i] + S[j]);
	// 答えの出力
	writeln(ans);
}
            
            
            
        