結果
| 問題 | No.17 2つの地点に泊まりたい | 
| コンテスト | |
| ユーザー |  ytft | 
| 提出日時 | 2022-11-03 06:51:03 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 74 ms / 5,000 ms | 
| コード長 | 1,155 bytes | 
| コンパイル時間 | 308 ms | 
| コンパイル使用メモリ | 82,376 KB | 
| 実行使用メモリ | 73,300 KB | 
| 最終ジャッジ日時 | 2024-07-17 17:41:31 | 
| 合計ジャッジ時間 | 2,726 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 27 | 
ソースコード
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)
            
            
            
        