結果
問題 | No.1812 Uribo Road |
ユーザー |
![]() |
提出日時 | 2023-02-24 05:54:52 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 767 bytes |
コンパイル時間 | 435 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 382,112 KB |
最終ジャッジ日時 | 2024-07-23 21:08:17 |
合計ジャッジ時間 | 9,143 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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)