結果
問題 | No.1814 Uribo Road (Easy) |
ユーザー | brthyyjp |
提出日時 | 2022-03-13 08:28:49 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 123 ms / 2,000 ms |
コード長 | 2,081 bytes |
コンパイル時間 | 157 ms |
コンパイル使用メモリ | 81,892 KB |
実行使用メモリ | 78,692 KB |
最終ジャッジ日時 | 2024-09-17 17:58:55 |
合計ジャッジ時間 | 5,891 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
53,248 KB |
testcase_01 | AC | 42 ms
53,760 KB |
testcase_02 | AC | 37 ms
53,192 KB |
testcase_03 | AC | 36 ms
52,736 KB |
testcase_04 | AC | 37 ms
53,120 KB |
testcase_05 | AC | 36 ms
53,248 KB |
testcase_06 | AC | 36 ms
53,504 KB |
testcase_07 | AC | 36 ms
52,992 KB |
testcase_08 | AC | 37 ms
53,224 KB |
testcase_09 | AC | 66 ms
71,680 KB |
testcase_10 | AC | 58 ms
66,816 KB |
testcase_11 | AC | 64 ms
70,912 KB |
testcase_12 | AC | 87 ms
76,544 KB |
testcase_13 | AC | 87 ms
76,596 KB |
testcase_14 | AC | 97 ms
76,572 KB |
testcase_15 | AC | 68 ms
73,728 KB |
testcase_16 | AC | 86 ms
76,052 KB |
testcase_17 | AC | 90 ms
76,312 KB |
testcase_18 | AC | 55 ms
64,640 KB |
testcase_19 | AC | 50 ms
64,128 KB |
testcase_20 | AC | 108 ms
77,944 KB |
testcase_21 | AC | 112 ms
76,604 KB |
testcase_22 | AC | 113 ms
78,124 KB |
testcase_23 | AC | 112 ms
77,784 KB |
testcase_24 | AC | 117 ms
78,208 KB |
testcase_25 | AC | 117 ms
78,208 KB |
testcase_26 | AC | 123 ms
78,492 KB |
testcase_27 | AC | 116 ms
78,592 KB |
testcase_28 | AC | 116 ms
78,692 KB |
testcase_29 | AC | 120 ms
78,612 KB |
testcase_30 | AC | 85 ms
77,952 KB |
testcase_31 | AC | 81 ms
77,836 KB |
testcase_32 | AC | 96 ms
76,700 KB |
testcase_33 | AC | 58 ms
67,968 KB |
testcase_34 | AC | 52 ms
65,700 KB |
testcase_35 | AC | 75 ms
76,700 KB |
testcase_36 | AC | 81 ms
76,340 KB |
testcase_37 | AC | 74 ms
76,544 KB |
testcase_38 | AC | 100 ms
76,668 KB |
testcase_39 | AC | 93 ms
76,300 KB |
testcase_40 | AC | 96 ms
76,716 KB |
testcase_41 | AC | 98 ms
78,208 KB |
testcase_42 | AC | 92 ms
76,856 KB |
testcase_43 | AC | 104 ms
76,632 KB |
testcase_44 | AC | 110 ms
77,156 KB |
testcase_45 | AC | 86 ms
76,192 KB |
testcase_46 | AC | 112 ms
78,480 KB |
ソースコード
import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline import heapq INF = 10**18 def dijkstra(s, edge): n = len(edge) dist = [INF]*n dist[s] = 0 edgelist = [] heapq.heappush(edgelist,(dist[s], s)) while edgelist: minedge = heapq.heappop(edgelist) if dist[minedge[1]] < minedge[0]: continue v = minedge[1] for e in edge[v]: if dist[e[1]] > dist[v]+e[0]: dist[e[1]] = dist[v]+e[0] heapq.heappush(edgelist,(dist[e[1]], e[1])) return dist def main(): n, m, k = map(int, input().split()) R = list(map(int, input().split())) R = [r-1 for r in R] toid = {} for i, r in enumerate(R): toid[r] = i g = [[] for i in range(n)] ABC = [] for i in range(m): a, b, c = map(int, input().split()) a, b = a-1, b-1 g[a].append((c, b)) g[b].append((c, a)) if i in toid: ABC.append((a, b, c)) dists = dijkstra(0, g) distt = dijkstra(n-1, g) D = [] for i in range(k): a, b = ABC[i][0], ABC[i][1] dista = dijkstra(a, g) distb = dijkstra(b, g) D.append([dista,distb]) dp = [[[INF]*2 for i in range(k)] for i in range(1<<k)] for i, (a, b, c) in enumerate(ABC): dp[1<<i][i][0] = dists[b]+c dp[1<<i][i][1] = dists[a]+c for s in range(1<<k): for i in range(k): if (s>>i)&1: continue ns = s|(1<<i) c = ABC[i][2] for j in range(k): if not ((s>>j)&1): continue if i == j: continue for x in range(2): for y in range(2): dp[ns][i][x] = min(dp[ns][i][x], dp[s][j][y]+D[i][1-x][ABC[j][y]]+c) ans = INF for i in range(k): for x in range(2): v = ABC[i][x] ans = min(ans, dp[(1<<k)-1][i][x]+distt[v]) print(ans) if __name__ == '__main__': main()