結果

問題 No.1812 Uribo Road
ユーザー vwxyzvwxyz
提出日時 2023-02-24 05:31:10
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 2,468 bytes
コンパイル時間 1,951 ms
コンパイル使用メモリ 86,992 KB
実行使用メモリ 839,848 KB
最終ジャッジ日時 2023-10-01 03:23:07
合計ジャッジ時間 7,764 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,424 KB
testcase_01 AC 73 ms
71,052 KB
testcase_02 AC 105 ms
76,532 KB
testcase_03 AC 421 ms
133,692 KB
testcase_04 AC 74 ms
71,280 KB
testcase_05 AC 77 ms
71,128 KB
testcase_06 AC 83 ms
76,264 KB
testcase_07 AC 144 ms
81,468 KB
testcase_08 AC 432 ms
128,564 KB
testcase_09 AC 644 ms
175,408 KB
testcase_10 AC 369 ms
120,272 KB
testcase_11 AC 260 ms
97,088 KB
testcase_12 MLE -
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
readline=sys.stdin.readline
import heapq

class Graph:
    def __init__(self,V,edges=False,graph=False,directed=False,weighted=False,inf=float("inf")):
        self.V=V
        self.directed=directed
        self.weighted=weighted
        self.inf=inf
        if graph:
            self.graph=graph
            self.edges=[]
            for i in range(self.V):
                if self.weighted:
                    for j,d in self.graph[i]:
                        if self.directed or not self.directed and i<=j:
                            self.edges.append((i,j,d))
                else:
                    for j in self.graph[i]:
                        if self.directed or not self.directed and i<=j:
                            self.edges.append((i,j))
        else:
            self.edges=edges
            self.graph=[[] for i in range(self.V)]
            if weighted:
                for i,j,d in self.edges:
                    self.graph[i].append((j,d))
                    if not self.directed:
                        self.graph[j].append((i,d))
            else:
                for i,j in self.edges:
                    self.graph[i].append(j)
                    if not self.directed:
                        self.graph[j].append(i)

    def Dijkstra(self,s,route_restoration=False):
        dist=[self.inf]*self.V
        dist[s]=0
        hq=[(0,s)]
        if route_restoration:
            parents=[None]*self.V
        while hq:
            dx,x=heapq.heappop(hq)
            if dist[x]<dx:
                continue
            for y,dy in self.graph[x]:
                if dist[y]>dx+dy:
                    dist[y]=dx+dy
                    if route_restoration:
                        parents[y]=x
                    heapq.heappush(hq,(dist[y],y))
        if route_restoration:
            return dist,parents
        else:
            return dist

N,M,K=map(int,readline().split())
R=list(map(int,readline().split()))
for k in range(K):
    R[k]-=1
ABC=[]
for _ in range(M):
    A,B,C=map(int,readline().split())
    A-=1;B-=1
    ABC.append((A,B,C))
edges=[]
for bit in range(1<<K):
    for A,B,C in ABC:
        edges.append((bit*N+A,bit*N+B,C))
        edges.append((bit*N+B,bit*N+A,C))
for k in range(K):
    A,B,C=ABC[R[k]]
    for bit in range(1<<K):
        edges.append((bit*N+A,(bit|1<<k)*N+B,C))
        edges.append((bit*N+B,(bit|1<<k)*N+A,C))
G=Graph(N<<K,edges=edges,weighted=True)
ans=G.Dijkstra(0)[-1]
print(ans)
0