結果

問題 No.1812 Uribo Road
ユーザー mkawa2mkawa2
提出日時 2022-01-14 23:23:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 849 ms / 5,000 ms
コード長 2,158 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 82,420 KB
実行使用メモリ 96,808 KB
最終ジャッジ日時 2024-11-20 14:42:02
合計ジャッジ時間 9,956 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,256 KB
testcase_01 AC 41 ms
53,200 KB
testcase_02 AC 53 ms
64,124 KB
testcase_03 AC 104 ms
77,336 KB
testcase_04 AC 40 ms
53,384 KB
testcase_05 AC 41 ms
53,208 KB
testcase_06 AC 41 ms
54,208 KB
testcase_07 AC 75 ms
73,908 KB
testcase_08 AC 148 ms
77,472 KB
testcase_09 AC 181 ms
77,784 KB
testcase_10 AC 127 ms
77,728 KB
testcase_11 AC 151 ms
77,900 KB
testcase_12 AC 432 ms
87,960 KB
testcase_13 AC 209 ms
87,400 KB
testcase_14 AC 214 ms
86,660 KB
testcase_15 AC 392 ms
84,840 KB
testcase_16 AC 347 ms
84,704 KB
testcase_17 AC 755 ms
93,488 KB
testcase_18 AC 241 ms
82,704 KB
testcase_19 AC 823 ms
95,244 KB
testcase_20 AC 849 ms
96,808 KB
testcase_21 AC 619 ms
93,336 KB
testcase_22 AC 503 ms
90,188 KB
testcase_23 AC 145 ms
77,432 KB
testcase_24 AC 49 ms
62,148 KB
testcase_25 AC 193 ms
80,992 KB
testcase_26 AC 131 ms
78,100 KB
testcase_27 AC 226 ms
81,040 KB
testcase_28 AC 356 ms
84,388 KB
testcase_29 AC 41 ms
53,724 KB
testcase_30 AC 166 ms
78,412 KB
testcase_31 AC 503 ms
86,544 KB
testcase_32 AC 117 ms
77,668 KB
testcase_33 AC 323 ms
86,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 18446744073709551615
# inf = 4294967295
md = 10**9+7
# md = 998244353

from heapq import *

def dijkstra(to, root=0):
    n = len(to)
    dist = [inf]*n
    dist[root] = 0
    hp = [(0, root)]
    while hp:
        d, u = heappop(hp)
        if d > dist[u]: continue
        for v, c in to[u]:
            nd = d+c
            if dist[v] <= nd: continue
            dist[v] = nd
            heappush(hp, (nd, v))

    return dist

n, m, k = LI()
rr = LI1()
to = [[] for _ in range(n)]
uvc = []
for i in range(m):
    u, v, c = LI1()
    c += 1
    to[u].append((v, c))
    to[v].append((u, c))
    uvc.append((u, v, c))

dists = []
for r in rr:
    u, v, _ = uvc[r]
    dists.append(dijkstra(to, u))
    dists.append(dijkstra(to, v))
# p2D(dists)

dp = [[inf]*(1 << k) for _ in range(k*2)]
for i, r in enumerate(rr):
    for j in range(2):
        ij = i*2+j
        dp[i*2+1-j][1 << i] = dists[ij][0]+uvc[r][2]
# p2D(dp)

def chmin(i, j, val):
    if val < dp[i][j]: dp[i][j] = val

for s in range(1, 1 << k):
    for ij in range(k*2):
        pre = dp[ij][s]
        if pre == inf: continue
        for ni in range(k):
            if s >> ni & 1: continue
            ns = s | 1 << ni
            r = rr[ni]
            c = uvc[r][2]
            # pDB(c)
            for nj in range(2):
                v = uvc[r][nj]
                chmin(ni*2+1-nj, ns, pre+dists[ij][v]+c)
# p2D(dp)

ans = inf
for ij in range(k*2):
    cur = dp[ij][-1]+dists[ij][n-1]
    if cur < ans: ans = cur
print(ans)
0