結果

問題 No.17 2つの地点に泊まりたい
ユーザー pluto77pluto77
提出日時 2016-07-18 08:28:50
言語 Python2
(2.7.18)
結果
AC  
実行時間 74 ms / 5,000 ms
コード長 504 bytes
コンパイル時間 238 ms
コンパイル使用メモリ 7,076 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-23 02:14:50
合計ジャッジ時間 1,962 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,816 KB
testcase_01 AC 9 ms
6,944 KB
testcase_02 AC 12 ms
6,944 KB
testcase_03 AC 69 ms
6,940 KB
testcase_04 AC 14 ms
6,940 KB
testcase_05 AC 46 ms
6,944 KB
testcase_06 AC 30 ms
6,940 KB
testcase_07 AC 24 ms
6,944 KB
testcase_08 AC 70 ms
6,940 KB
testcase_09 AC 74 ms
6,940 KB
testcase_10 AC 59 ms
6,940 KB
testcase_11 AC 71 ms
6,940 KB
testcase_12 AC 10 ms
6,944 KB
testcase_13 AC 9 ms
6,940 KB
testcase_14 AC 9 ms
6,944 KB
testcase_15 AC 9 ms
6,940 KB
testcase_16 AC 10 ms
6,940 KB
testcase_17 AC 16 ms
6,940 KB
testcase_18 AC 56 ms
6,944 KB
testcase_19 AC 51 ms
6,948 KB
testcase_20 AC 15 ms
6,940 KB
testcase_21 AC 11 ms
6,940 KB
testcase_22 AC 65 ms
6,944 KB
testcase_23 AC 47 ms
6,940 KB
testcase_24 AC 55 ms
6,940 KB
testcase_25 AC 11 ms
6,944 KB
testcase_26 AC 63 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#coding: utf-8
#yuki_17

INF=float("inf")
n=int(raw_input())
s=[int(raw_input()) for i in xrange(n)]
m=int(raw_input())
d=[[INF for i in xrange(n)] for j in xrange(n)]
for i in xrange(m):
 a,b,c=map(int,raw_input().split())
 d[a][b]=d[b][a]=c

for k in xrange(n):
 for i in xrange(n):
  for j in xrange(n):
   d[i][j]=min(d[i][j],d[i][k]+d[k][j])

res=INF
for i in xrange(1,n-1):
 for j in xrange(1,n-1):
  if i==j:
   continue
  cost=d[0][i]+d[i][j]+d[j][n-1]+s[i]+s[j]
  res=min(res,cost)
  
print res
0