結果
問題 | No.1814 Uribo Road (Easy) |
ユーザー | Shirotsume |
提出日時 | 2021-12-30 00:04:33 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 277 ms / 2,000 ms |
コード長 | 1,547 bytes |
コンパイル時間 | 268 ms |
コンパイル使用メモリ | 82,788 KB |
実行使用メモリ | 79,648 KB |
最終ジャッジ日時 | 2024-05-01 17:33:00 |
合計ジャッジ時間 | 7,146 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
52,736 KB |
testcase_01 | AC | 38 ms
52,992 KB |
testcase_02 | AC | 39 ms
52,992 KB |
testcase_03 | AC | 42 ms
53,376 KB |
testcase_04 | AC | 39 ms
53,248 KB |
testcase_05 | AC | 38 ms
52,608 KB |
testcase_06 | AC | 37 ms
53,224 KB |
testcase_07 | AC | 37 ms
52,864 KB |
testcase_08 | AC | 38 ms
53,248 KB |
testcase_09 | AC | 121 ms
76,640 KB |
testcase_10 | AC | 65 ms
65,536 KB |
testcase_11 | AC | 68 ms
70,656 KB |
testcase_12 | AC | 120 ms
77,776 KB |
testcase_13 | AC | 130 ms
77,624 KB |
testcase_14 | AC | 170 ms
77,724 KB |
testcase_15 | AC | 97 ms
76,544 KB |
testcase_16 | AC | 117 ms
76,432 KB |
testcase_17 | AC | 108 ms
76,636 KB |
testcase_18 | AC | 70 ms
72,064 KB |
testcase_19 | AC | 91 ms
77,056 KB |
testcase_20 | AC | 144 ms
78,228 KB |
testcase_21 | AC | 134 ms
78,084 KB |
testcase_22 | AC | 148 ms
78,348 KB |
testcase_23 | AC | 143 ms
78,208 KB |
testcase_24 | AC | 174 ms
78,432 KB |
testcase_25 | AC | 186 ms
78,756 KB |
testcase_26 | AC | 248 ms
78,840 KB |
testcase_27 | AC | 267 ms
79,076 KB |
testcase_28 | AC | 264 ms
79,092 KB |
testcase_29 | AC | 277 ms
79,648 KB |
testcase_30 | AC | 189 ms
78,808 KB |
testcase_31 | AC | 193 ms
78,336 KB |
testcase_32 | AC | 143 ms
78,504 KB |
testcase_33 | AC | 64 ms
68,224 KB |
testcase_34 | AC | 69 ms
70,400 KB |
testcase_35 | AC | 83 ms
77,128 KB |
testcase_36 | AC | 137 ms
77,684 KB |
testcase_37 | AC | 76 ms
75,516 KB |
testcase_38 | AC | 178 ms
77,744 KB |
testcase_39 | AC | 152 ms
77,872 KB |
testcase_40 | AC | 133 ms
77,756 KB |
testcase_41 | AC | 109 ms
78,336 KB |
testcase_42 | AC | 117 ms
77,696 KB |
testcase_43 | AC | 147 ms
77,796 KB |
testcase_44 | AC | 175 ms
78,028 KB |
testcase_45 | AC | 115 ms
77,056 KB |
testcase_46 | AC | 147 ms
78,244 KB |
ソースコード
import heapq import sys input = lambda: sys.stdin.readline().rstrip() n, m, k = map(int,input().split()) r = list(map(int,input().split())) for i in range(k): r[i] -= 1 graph = [[] for _ in range(n)] r_n = len(r) r_edges = {} r.sort() for i in range(m): a, b, c = map(int,input().split()) if b < a: a, b = b, a graph[a - 1].append((b - 1, c)) graph[b - 1].append((a - 1, c)) if i in r: r_edges[(a - 1, b - 1)] = r.index(i) def dijkstra(n, graph): INF = 10 ** 15 dist = [[INF] * (2 ** r_n) for _ in range(n)] dist[0][0] = 0 hq = [] heapq.heappush(hq, (0, 0, 0)) visit = [[False] * (2 ** r_n) for _ in range(n)] visit[0][0] = True while hq: c, v, bit = heapq.heappop(hq) if c > dist[v][bit]: continue visit[v][bit] = True for to, cost in graph[v]: if (min(v, to), max(v, to)) in r_edges: msk = 1 << r_edges[(min(v, to), max(v, to))] if visit[to][bit | msk] == False and dist[v][bit] + cost < dist[to][bit | msk]: dist[to][bit | msk] = dist[v][bit] + cost heapq.heappush(hq, (dist[to][bit | msk], to, bit | msk)) elif visit[to][bit] == False and dist[v][bit] + cost < dist[to][bit]: dist[to][bit] = dist[v][bit] + cost heapq.heappush(hq, (dist[to][bit], to, bit)) return dist ans = dijkstra(n, graph) print(ans[n - 1][2 ** r_n - 1])