結果
| 問題 |
No.1812 Uribo Road
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-01-14 23:40:39 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 926 bytes |
| コンパイル時間 | 575 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 607,872 KB |
| 最終ジャッジ日時 | 2024-11-20 15:44:04 |
| 合計ジャッジ時間 | 81,394 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 TLE * 11 MLE * 1 |
ソースコード
import sys
r = sys.stdin
N,M,K = map(int,r.readline().split())
R = list(map(int,r.readline().split()))
Rset = set(R)
G = [[] for _ in range(N+1)]
#D = {v:i for i,v in enumerate(sorted(set(R)))}
edge = dict()
for i in range(M):
a,b,c = map(int,r.readline().split())
G[a].append((b,c))
G[b].append((a,c))
if i + 1 not in Rset:continue
for j in range(K):
if R[j] == i + 1:
edge[(a,b)] = j
edge[(b,a)] = j
C = 10 ** 15
dp = [[C] * (1<<K) for _ in range(N+1)]
dp[0][0] = 0
import heapq
q = []
heapq.heapify(q)
heapq.heappush(q,(0,1,0))
while q:
d,now,S = heapq.heappop(q)
if d == N and S == (1 << K) - 1:break
if d > dp[now][S]:continue
for v,c in G[now]:
if (now,v) in edge:
T = S | (1 << edge[(now,v)])
else:T = S
if dp[v][T] > d + c:
dp[v][T] = d+c
heapq.heappush(q,(d+c,v,T))
print(dp[N][(1<<K)-1])