結果
問題 | No.1301 Strange Graph Shortest Path |
ユーザー | yuusanlondon |
提出日時 | 2020-11-27 22:25:45 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,166 bytes |
コンパイル時間 | 445 ms |
コンパイル使用メモリ | 86,488 KB |
実行使用メモリ | 150,384 KB |
最終ジャッジ日時 | 2023-10-09 21:28:11 |
合計ジャッジ時間 | 42,838 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 76 ms
70,956 KB |
testcase_01 | AC | 76 ms
71,004 KB |
testcase_02 | WA | - |
testcase_03 | AC | 1,109 ms
135,828 KB |
testcase_04 | AC | 1,311 ms
150,340 KB |
testcase_05 | AC | 1,242 ms
142,464 KB |
testcase_06 | AC | 1,243 ms
145,252 KB |
testcase_07 | AC | 1,304 ms
144,376 KB |
testcase_08 | AC | 1,189 ms
137,504 KB |
testcase_09 | AC | 1,181 ms
141,868 KB |
testcase_10 | WA | - |
testcase_11 | AC | 1,301 ms
145,924 KB |
testcase_12 | AC | 1,249 ms
146,428 KB |
testcase_13 | AC | 1,315 ms
146,216 KB |
testcase_14 | AC | 1,218 ms
140,856 KB |
testcase_15 | AC | 1,240 ms
141,052 KB |
testcase_16 | AC | 1,258 ms
150,384 KB |
testcase_17 | AC | 1,316 ms
147,644 KB |
testcase_18 | AC | 1,295 ms
139,632 KB |
testcase_19 | AC | 1,282 ms
146,600 KB |
testcase_20 | AC | 1,105 ms
144,784 KB |
testcase_21 | AC | 1,271 ms
145,092 KB |
testcase_22 | AC | 1,060 ms
145,108 KB |
testcase_23 | AC | 1,424 ms
145,624 KB |
testcase_24 | AC | 1,185 ms
146,412 KB |
testcase_25 | AC | 1,315 ms
149,148 KB |
testcase_26 | AC | 1,352 ms
144,216 KB |
testcase_27 | AC | 1,248 ms
144,096 KB |
testcase_28 | AC | 1,269 ms
142,380 KB |
testcase_29 | WA | - |
testcase_30 | AC | 1,363 ms
148,392 KB |
testcase_31 | AC | 1,368 ms
148,580 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | AC | 1,237 ms
146,224 KB |
ソースコード
import heapq INF=10**20 def Dijkstra(graph, start): dist=[INF]*len(graph) parent=[INF]*len(graph) queue=[(0, start, INF)] while queue: path_len, v, parent1=heapq.heappop(queue) if dist[v]==INF: dist[v]=path_len parent[v]=parent1 for w in graph[v]: if dist[w[0]]==INF: heapq.heappush(queue, (dist[v]+w[1], w[0], v)) return (dist,parent) n,m=map(int,input().split()) graph=[] for i in range(n): graph.append([]) edges=[] for _ in range(m): u,v,c,d=map(int,input().split()) edges.append([u,v,c,d]) graph[u-1].append((v-1,c)) graph[v-1].append((u-1,c)) dist,parent=Dijkstra(graph,0) ans=dist[n-1] point=n-1 used=set() while point!=0: used.add(parent[point]*(10**10)+point) used.add(point*(10**10)+parent[point]) point=parent[point] graph=[] for i in range(n): graph.append([]) for i in range(m): u=edges[i][0] v=edges[i][1] c=edges[i][2] d=edges[i][3] if (u-1)*(10**10)+(v-1) in used: graph[u-1].append([v-1,d]) graph[v-1].append([u-1,d]) else: graph[u-1].append([v-1,c]) graph[v-1].append([u-1,c]) dist,parent=Dijkstra(graph,0) ans+=dist[n-1] print(ans)