結果

問題 No.1812 Uribo Road
ユーザー vwxyzvwxyz
提出日時 2023-02-24 05:31:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 2,468 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 11,076 KB
実行使用メモリ 817,600 KB
最終ジャッジ日時 2023-10-01 03:22:57
合計ジャッジ時間 10,003 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,416 KB
testcase_01 AC 18 ms
8,240 KB
testcase_02 AC 20 ms
8,828 KB
testcase_03 AC 518 ms
86,864 KB
testcase_04 AC 17 ms
8,388 KB
testcase_05 AC 17 ms
8,404 KB
testcase_06 AC 18 ms
8,636 KB
testcase_07 AC 50 ms
13,952 KB
testcase_08 AC 551 ms
80,940 KB
testcase_09 AC 1,148 ms
146,780 KB
testcase_10 AC 440 ms
69,136 KB
testcase_11 AC 210 ms
35,324 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