結果
問題 |
No.17 2つの地点に泊まりたい
|
ユーザー |
![]() |
提出日時 | 2017-06-01 20:38:47 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 80 ms / 5,000 ms |
コード長 | 1,314 bytes |
コンパイル時間 | 424 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 11,776 KB |
最終ジャッジ日時 | 2024-10-15 01:40:57 |
合計ジャッジ時間 | 2,649 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
ソースコード
# coding: utf-8 import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time sys.setrecursionlimit(10 ** 7) INF = 10 ** 20 MOD = 10 ** 9 + 7 def II(): return int(input()) def ILI(): return list(map(int, input().split())) def IAI(LINE): return [ILI() for __ in range(LINE)] def IDI(): return {key: value for key, value in ILI()} def read(): N = II() S = [II() for __ in range(N)] M = II() A, B, C = list(), list(), list() for __ in range(M): a, b, c = ILI() A.append(a) B.append(b) C.append(c) return (N, S, M, A, B, C) def solve(N, S, M, A, B, C): edge = [[INF] * N for __ in range(N)] for a, b, c in zip(A, B, C): edge[a][b] = c edge[b][a] = c for i in range(N): edge[i][i] = 0 for k in range(N): for i in range(N): for j in range(N): edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j]) ans = INF for a in range(1, N - 1): for b in range(1, N - 1): if a == b: continue cost = S[a] + S[b] + edge[0][a] + edge[a][b] + edge[b][N - 1] ans = min(ans, cost) return ans def main(): params = read() print(solve(*params)) if __name__ == "__main__": main()