結果
| 問題 |
No.1812 Uribo Road
|
| コンテスト | |
| ユーザー |
vwxyz
|
| 提出日時 | 2023-02-24 05:54:42 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 767 bytes |
| コンパイル時間 | 201 ms |
| コンパイル使用メモリ | 82,356 KB |
| 実行使用メモリ | 459,976 KB |
| 最終ジャッジ日時 | 2024-07-23 21:07:45 |
| 合計ジャッジ時間 | 9,312 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 8 TLE * 1 -- * 21 |
ソースコード
import sys
readline=sys.stdin.readline
import heapq
N,M,K=map(int,readline().split())
R=list(map(int,readline().split()))
graph=[[] for x in range(N)]
idx=[-1]*M
for k in range(K):
R[k]-=1
idx[R[k]]=k
for m in range(M):
A,B,C=map(int,readline().split())
A-=1;B-=1
graph[A].append((B,C,idx[m]))
graph[B].append((A,C,idx[m]))
inf=1<<30
dist=[[inf]*N for bit in range(1<<K)]
dist[0][0]=0
queue=[]
queue=[(0,0,0)]
while queue:
dx,bitx,x=heapq.heappop(queue)
if dist[bitx][x]<dx:
continue
for y,dy,i in graph[x]:
bity=bitx
if i!=-1:
bity|=1<<i
if dist[bity][y]>dx+dy:
dist[bity][y]=dx+dy
heapq.heappush(queue,(dist[bity][y],bity,y))
ans=dist[(1<<K)-1][N-1]
print(ans)
vwxyz