結果

問題 No.1814 Uribo Road (Easy)
ユーザー rlangevinrlangevin
提出日時 2024-01-10 12:46:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 495 ms / 2,000 ms
コード長 1,379 bytes
コンパイル時間 338 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 77,780 KB
最終ジャッジ日時 2024-01-10 12:46:37
合計ジャッジ時間 10,403 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,588 KB
testcase_01 AC 43 ms
59,732 KB
testcase_02 AC 39 ms
53,588 KB
testcase_03 AC 38 ms
53,588 KB
testcase_04 AC 34 ms
53,588 KB
testcase_05 AC 34 ms
53,588 KB
testcase_06 AC 36 ms
59,092 KB
testcase_07 AC 34 ms
53,588 KB
testcase_08 AC 38 ms
53,588 KB
testcase_09 AC 85 ms
72,664 KB
testcase_10 AC 56 ms
66,176 KB
testcase_11 AC 56 ms
68,772 KB
testcase_12 AC 71 ms
73,060 KB
testcase_13 AC 81 ms
74,224 KB
testcase_14 AC 171 ms
76,624 KB
testcase_15 AC 86 ms
68,352 KB
testcase_16 AC 243 ms
75,776 KB
testcase_17 AC 427 ms
75,916 KB
testcase_18 AC 117 ms
70,400 KB
testcase_19 AC 249 ms
75,776 KB
testcase_20 AC 106 ms
77,224 KB
testcase_21 AC 166 ms
76,500 KB
testcase_22 AC 105 ms
77,520 KB
testcase_23 AC 104 ms
76,824 KB
testcase_24 AC 176 ms
77,420 KB
testcase_25 AC 170 ms
77,272 KB
testcase_26 AC 435 ms
77,764 KB
testcase_27 AC 452 ms
77,780 KB
testcase_28 AC 477 ms
77,780 KB
testcase_29 AC 483 ms
77,780 KB
testcase_30 AC 495 ms
77,780 KB
testcase_31 AC 468 ms
77,780 KB
testcase_32 AC 155 ms
76,504 KB
testcase_33 AC 60 ms
68,384 KB
testcase_34 AC 57 ms
68,392 KB
testcase_35 AC 60 ms
70,964 KB
testcase_36 AC 99 ms
76,552 KB
testcase_37 AC 67 ms
68,888 KB
testcase_38 AC 197 ms
76,744 KB
testcase_39 AC 102 ms
76,528 KB
testcase_40 AC 85 ms
74,864 KB
testcase_41 AC 77 ms
77,388 KB
testcase_42 AC 79 ms
76,980 KB
testcase_43 AC 125 ms
76,528 KB
testcase_44 AC 200 ms
76,864 KB
testcase_45 AC 88 ms
76,372 KB
testcase_46 AC 121 ms
77,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from math import *
inf = 10 ** 18

def dist(a, b):
    return max(0, sqrt((X[a] - X[b])**2 + (Y[a] - Y[b])**2) - R[a] - R[b])


def dijkstra(G, K2):
    ind = (0, 0)
    N = len(G)
    seen = [[0] * N for _ in range(K2)]
    D = [[inf] * N for _ in range(K2)]
    D[0][0] = 0
    while True:
        minv = inf
        for s in range(K2):
            for i in range(N):
                if seen[s][i]:
                    continue
                if D[s][i] < minv:
                    ind = (s, i)
                    minv = D[s][i]
        if ind == (K2-1, N-1):
            break
        
        seen[ind[0]][ind[1]] = 1
        s = ind[0]
        for i in range(N):
            if G[ind[1]][i] == inf:
                continue
            ns = s
            if RR[G[ind[1]][i][1]] != -1:
                ns = s | (1 << RR[G[ind[1]][i][1]])
            if seen[ns][i]:
                continue
            D[ns][i] = min(D[ns][i], D[ind[0]][ind[1]] + G[ind[1]][i][0])
                        
    return D[K2-1][N-1]


N, M, K = map(int, input().split())
R = list(map(int, input().split()))
RR = [-1] * M
for i in range(K):
    RR[R[i]-1] = i
    
G = [[inf] * N for _ in range(N)]
for i in range(M):
    A, B, C = map(int, input().split())
    A, B = A - 1, B - 1
    G[A][B] = (C, i)
    G[B][A] = (C, i)
    
print(dijkstra(G, 1 << K))
0