結果

問題 No.17 2つの地点に泊まりたい
ユーザー Yuta123456Yuta123456
提出日時 2020-05-21 21:31:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 933 ms / 5,000 ms
コード長 697 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 56,384 KB
最終ジャッジ日時 2024-04-10 05:31:24
合計ジャッジ時間 30,942 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 919 ms
56,120 KB
testcase_01 AC 920 ms
56,304 KB
testcase_02 AC 921 ms
56,092 KB
testcase_03 AC 926 ms
56,112 KB
testcase_04 AC 917 ms
56,112 KB
testcase_05 AC 916 ms
55,996 KB
testcase_06 AC 912 ms
56,244 KB
testcase_07 AC 925 ms
56,244 KB
testcase_08 AC 933 ms
56,380 KB
testcase_09 AC 932 ms
56,240 KB
testcase_10 AC 920 ms
55,992 KB
testcase_11 AC 918 ms
56,372 KB
testcase_12 AC 915 ms
56,384 KB
testcase_13 AC 919 ms
56,124 KB
testcase_14 AC 904 ms
56,248 KB
testcase_15 AC 910 ms
55,988 KB
testcase_16 AC 921 ms
56,120 KB
testcase_17 AC 923 ms
55,992 KB
testcase_18 AC 914 ms
55,996 KB
testcase_19 AC 919 ms
56,248 KB
testcase_20 AC 918 ms
56,112 KB
testcase_21 AC 903 ms
56,120 KB
testcase_22 AC 915 ms
56,372 KB
testcase_23 AC 920 ms
56,116 KB
testcase_24 AC 923 ms
56,112 KB
testcase_25 AC 918 ms
56,112 KB
testcase_26 AC 931 ms
56,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
n = int(input())
graph = [[0 for i in range(n)] for j in range(n)]
stay_cost = [int(input()) for i in range(n)]
for i in range(int(input())):
    a,b,c = map(int, input().split())
    graph[a][b] = graph[b][a] = c
graph = dijkstra(graph)
ans = 10**18
for i in range(1,n-1):
    for j in range(1,n-1):
        if i == j:
            continue
        #print("i:{} j:{}".format(i,j))
        ans = min(ans,
                  graph[0][i] + graph[i][j] + graph[j][n-1] +
                  stay_cost[i] + stay_cost[j] 
                )
print(int(ans))
0