結果

問題 No.17 2つの地点に泊まりたい
ユーザー fmhrfmhr
提出日時 2015-06-12 20:52:51
言語 Go1.4
(1.4.2)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,208 bytes
コンパイル時間 1,987 ms
コンパイル使用メモリ 33,964 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-05 03:33:50
合計ジャッジ時間 3,151 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var INF int = 10000*50*1000 + 1

func main() {
	N := nextInt()
	S := make([]int, N)
	for i := 0; i < N; i++ {
		S[i] = nextInt()
	}
	M := nextInt()
	d := makeDoubleSliceInt(N, N)
	for i := 0; i < M; i++ {
		A := nextInt()
		B := nextInt()
		C := nextInt()
		d[A][B] = C
		d[B][A] = C
	}
	for k := 0; k < N; k++ {
		for i := 0; i < N; i++ {
			for j := 0; j < N; j++ {
				d[i][j] = min(d[i][j], d[i][k]+d[k][j])
			}

		}
	}
	ans := INF
	for i := 1; i < N-1; i++ {
		for j := 1; j < N-1; j++ {
			if i == j {
				continue
			}
			ans = min(ans, d[0][i]+d[i][j]+d[j][N-1]+S[i]+S[j])
		}
	}
	fmt.Println(ans)
	//fmt.Println(d)
	//fmt.Println(S)
}

func min(a, b int) int {
	if a < b {
		a, b = b, a
	}
	return b
}

var s = bufio.NewScanner(os.Stdin)

func next() string {
	s.Split(bufio.ScanWords)
	s.Scan()
	return s.Text()
}

func nextInt() int {
	i, e := strconv.Atoi(next())
	if e != nil {
		panic(e)
	}
	return i
}

func makeDoubleSliceInt(y, x int) [][]int {
	ss := make([][]int, y)
	for i := range ss {
		ss[i] = make([]int, x)
		for j := 0; j < x; j++ {
			if i == j {
				ss[i][j] = 0
			} else {
				ss[i][j] = INF

			}
		}
	}
	return ss
}
0