結果

問題 No.17 2つの地点に泊まりたい
ユーザー ytftytft
提出日時 2022-11-03 06:51:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 103 ms / 5,000 ms
コード長 1,155 bytes
コンパイル時間 1,489 ms
コンパイル使用メモリ 86,496 KB
実行使用メモリ 76,760 KB
最終ジャッジ日時 2023-09-24 16:47:47
合計ジャッジ時間 4,831 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
70,904 KB
testcase_01 AC 69 ms
70,900 KB
testcase_02 AC 69 ms
71,040 KB
testcase_03 AC 88 ms
76,384 KB
testcase_04 AC 78 ms
75,724 KB
testcase_05 AC 92 ms
76,340 KB
testcase_06 AC 89 ms
76,372 KB
testcase_07 AC 82 ms
75,904 KB
testcase_08 AC 103 ms
76,556 KB
testcase_09 AC 101 ms
76,760 KB
testcase_10 AC 87 ms
76,344 KB
testcase_11 AC 92 ms
76,348 KB
testcase_12 AC 71 ms
71,084 KB
testcase_13 AC 69 ms
71,080 KB
testcase_14 AC 70 ms
71,200 KB
testcase_15 AC 70 ms
70,944 KB
testcase_16 AC 70 ms
71,064 KB
testcase_17 AC 71 ms
71,072 KB
testcase_18 AC 91 ms
76,504 KB
testcase_19 AC 93 ms
76,664 KB
testcase_20 AC 73 ms
71,152 KB
testcase_21 AC 72 ms
70,964 KB
testcase_22 AC 93 ms
76,676 KB
testcase_23 AC 91 ms
76,204 KB
testcase_24 AC 97 ms
76,348 KB
testcase_25 AC 80 ms
75,628 KB
testcase_26 AC 98 ms
76,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda:sys.stdin.readline().rstrip()
class node:
    def __init__(self,con):
        self.con=con
class directedWeightedGraph:
    def __init__(self,N,edges=[]):
        self.N=N
        self.nodes=[node([]) for i in range(N)]
        for i in edges:
            self.nodes[i[0]].append(i[1:])
    def connect(self,f,t,weight=0):
        self.nodes[f].con.append([t,weight])
    def dijkstra(self,start):
        ans=[float('inf') for i in range(self.N)]
        ans[start]=0
        watch=[start]
        while len(watch):
            cur=watch[-1]
            watch.pop()
            for i in self.nodes[cur].con:
                if ans[i[0]]>ans[cur]+i[1]:
                    ans[i[0]]=ans[cur]+i[1]
                    watch.append(i[0])
        return ans
N=int(input())
S=[int(input()) for i in range(N)]
G=directedWeightedGraph(N)
M=int(input())
for i in range(M):
	A,B,C=map(int,input().split())
	G.connect(A,B,C)
	G.connect(B,A,C)
dist=[G.dijkstra(i) for i in range(N)]
ans=float('inf')
for i in range(1,N-1):
	for j in range(1,N-1):
		if i==j:
			continue
		ans=min(ans,S[i]+S[j]+dist[0][i]+dist[i][j]+dist[j][N-1])
print(ans)
0