結果
問題 | No.1812 Uribo Road |
ユーザー | MasKoaTS |
提出日時 | 2021-12-22 13:35:55 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,352 bytes |
コンパイル時間 | 313 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 132,864 KB |
最終ジャッジ日時 | 2024-09-16 07:51:23 |
合計ジャッジ時間 | 7,534 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
53,120 KB |
testcase_01 | AC | 43 ms
52,864 KB |
testcase_02 | AC | 77 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 = [(s,0)] dist = [INF] * N while(que): v,d = hq.heappop(que) if(dist[v] < INF): continue dist[v] = d for nv,nd in route[v]: hq.heappush(que,(nv,d + nd)) 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)