結果

問題 No.17 2つの地点に泊まりたい
ユーザー ytftytft
提出日時 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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,576 KB
testcase_01 AC 38 ms
52,804 KB
testcase_02 AC 38 ms
52,940 KB
testcase_03 AC 57 ms
65,700 KB
testcase_04 AC 48 ms
62,272 KB
testcase_05 AC 66 ms
69,524 KB
testcase_06 AC 59 ms
66,284 KB
testcase_07 AC 52 ms
64,432 KB
testcase_08 AC 74 ms
73,300 KB
testcase_09 AC 74 ms
72,612 KB
testcase_10 AC 59 ms
66,296 KB
testcase_11 AC 63 ms
67,120 KB
testcase_12 AC 37 ms
53,108 KB
testcase_13 AC 37 ms
52,748 KB
testcase_14 AC 37 ms
52,608 KB
testcase_15 AC 37 ms
52,876 KB
testcase_16 AC 38 ms
52,604 KB
testcase_17 AC 39 ms
55,480 KB
testcase_18 AC 59 ms
67,652 KB
testcase_19 AC 57 ms
66,204 KB
testcase_20 AC 39 ms
53,916 KB
testcase_21 AC 39 ms
53,780 KB
testcase_22 AC 60 ms
67,768 KB
testcase_23 AC 62 ms
69,044 KB
testcase_24 AC 62 ms
66,736 KB
testcase_25 AC 47 ms
61,768 KB
testcase_26 AC 66 ms
69,036 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