結果

問題 No.1812 Uribo Road
ユーザー ygd.ygd.
提出日時 2022-01-14 22:50:32
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,783 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 82,456 KB
実行使用メモリ 447,448 KB
最終ジャッジ日時 2024-04-30 16:32:57
合計ジャッジ時間 8,587 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,744 KB
testcase_01 AC 41 ms
53,632 KB
testcase_02 AC 40 ms
53,472 KB
testcase_03 AC 256 ms
78,432 KB
testcase_04 AC 39 ms
53,688 KB
testcase_05 AC 41 ms
53,664 KB
testcase_06 AC 43 ms
52,948 KB
testcase_07 AC 47 ms
60,480 KB
testcase_08 AC 285 ms
78,944 KB
testcase_09 AC 465 ms
82,292 KB
testcase_10 AC 241 ms
78,600 KB
testcase_11 AC 203 ms
77,876 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline #文字列につけてはダメ
input = sys.stdin.buffer.readline #文字列につけてはダメ
#sys.setrecursionlimit(1000000)
#import bisect
#import itertools
#import random
from heapq import heapify, heappop, heappush
#from collections import defaultdict 
#from collections import deque
#import copy
#import math
#from functools import lru_cache
#MOD = pow(10,9) + 7
#MOD = 998244353


def main():
    N,M,K = map(int,input().split())
    R = list(map(int,input().split()))
    R = [r-1 for r in R]
    R.sort()
    dic = {}
    req = 0
    G = [[] for _ in range(N)]
    for i in range(M):
        a,b,c = map(int,input().split())
        a -= 1; b -= 1
        G[a].append((c,b))
        G[b].append((c,a))
        if req < K and i == R[req]:
            dic[(a,b)] = req
            dic[(b,a)] = req
            req += 1
    #print(dic)

    dis = dijkstra_heap2(0,K,G,dic)
    ans = dis[-1]
    print(ans)

def dijkstra_heap2(s,K,G,dic):
    INF = pow(10,18)
    #S:start, V: node, E: Edge, G: Graph
    V = len(G)
    K2 = 1 << K
    #d[i][j]: i番目の頂点にいて通った道の状態がjの時の最短経路
    #idx = i * K2 + j 
    d = [INF for _ in range(V * K2)]
    d[s] = 0
    PQ = []
    heappush(PQ,(0,s))

    while PQ:
        c,vidx = heappop(PQ)
        vi = vidx // K2
        vj = vidx % K2
        if d[vidx] < c:
            continue
        d[vidx] = c
        for cost,ui in G[vi]:
            uj = vj
            if (vi,ui) in dic:
                uj = vj | 1 << dic[(vi,ui)]
            uidx = ui * K2 + uj
            if d[uidx] <= cost + d[vidx]:
                continue
            d[uidx] = cost + d[vidx]
            heappush(PQ,(d[uidx], uidx))

    return d

if __name__ == '__main__':
    main()
0