結果
問題 | No.1812 Uribo Road |
ユーザー | MasKoaTS |
提出日時 | 2021-12-22 13:38:52 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,353 bytes |
コンパイル時間 | 164 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 136,980 KB |
最終ジャッジ日時 | 2024-10-07 00:48:41 |
合計ジャッジ時間 | 6,784 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
53,504 KB |
testcase_01 | AC | 38 ms
53,120 KB |
testcase_02 | AC | 70 ms
69,760 KB |
testcase_03 | TLE | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
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 | -- | - |
ソースコード
import heapq as hq import sys input = sys.stdin.readline INF = 10 ** 18 N,M,K = map(int, input().split()) R = [i - 1 for i in map(int, input().split())] S = set(R) edge = [[] for _ in [0] * M] route = [[] for _ in [0] * N] rsum = 0 for i in range(M): a,b,c = map(int, input().split()) a -= 1; b -= 1 route[a].append((b,c)) route[b].append((a,c)) if(i in S): edge[i] = [a,b,c] rsum += c def dijkstra(s,route): que = [(0,s)] dist = [INF] * N while(que): d,v = hq.heappop(que) if(dist[v] < INF): continue dist[v] = d for nv,nd in route[v]: hq.heappush(que,(d + nd, nv)) return dist dist = [[] for _ in [0] * N] T = set([0,N - 1]) for i in S: T.add(edge[i][0]) T.add(edge[i][1]) for i in T: dist[i] = dijkstra(i,route) ans = INF for rbit in range(1 << K): b = [(rbit >> i) & 1 for i in range(K)] dp = [[INF] * K for _ in [0] * (1 << K)] for i in range(K): k = edge[R[i]][b[i]] dp[1 << i][i] = rsum + dist[0][k] for bit in range(1, 1 << K): for s in range(K): if not(bit & (1 << s)): continue k = edge[R[s]][b[s] ^ 1] for t in range(K): l = edge[R[t]][b[t]] p = bit | (1 << t) q = dp[bit][s] + dist[k][l] if((bit & (1 << t)) == 0 and dp[p][t] > q): dp[p][t] = q for i in range(K): k = edge[R[i]][b[i] ^ 1] d = dp[-1][i] + dist[k][N - 1] if(ans > d): ans = d print(ans)