結果

問題 No.1812 Uribo Road
ユーザー mkawa2mkawa2
提出日時 2022-01-14 23:23:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 880 ms / 5,000 ms
コード長 2,158 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 82,792 KB
実行使用メモリ 96,588 KB
最終ジャッジ日時 2024-04-30 17:27:03
合計ジャッジ時間 10,709 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,416 KB
testcase_01 AC 44 ms
53,600 KB
testcase_02 AC 57 ms
63,796 KB
testcase_03 AC 107 ms
77,536 KB
testcase_04 AC 40 ms
53,144 KB
testcase_05 AC 41 ms
53,412 KB
testcase_06 AC 46 ms
55,496 KB
testcase_07 AC 74 ms
73,124 KB
testcase_08 AC 151 ms
77,476 KB
testcase_09 AC 186 ms
78,292 KB
testcase_10 AC 132 ms
77,580 KB
testcase_11 AC 156 ms
78,156 KB
testcase_12 AC 466 ms
87,900 KB
testcase_13 AC 219 ms
87,280 KB
testcase_14 AC 222 ms
87,272 KB
testcase_15 AC 411 ms
84,704 KB
testcase_16 AC 373 ms
84,584 KB
testcase_17 AC 811 ms
93,600 KB
testcase_18 AC 249 ms
82,828 KB
testcase_19 AC 870 ms
95,504 KB
testcase_20 AC 880 ms
96,588 KB
testcase_21 AC 672 ms
93,208 KB
testcase_22 AC 531 ms
90,448 KB
testcase_23 AC 153 ms
77,732 KB
testcase_24 AC 56 ms
60,892 KB
testcase_25 AC 219 ms
81,620 KB
testcase_26 AC 149 ms
77,988 KB
testcase_27 AC 247 ms
81,420 KB
testcase_28 AC 400 ms
84,508 KB
testcase_29 AC 44 ms
53,408 KB
testcase_30 AC 178 ms
78,796 KB
testcase_31 AC 551 ms
86,800 KB
testcase_32 AC 130 ms
77,288 KB
testcase_33 AC 344 ms
86,824 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