結果
| 問題 |
No.1301 Strange Graph Shortest Path
|
| コンテスト | |
| ユーザー |
yuusanlondon
|
| 提出日時 | 2020-11-27 22:25:45 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,166 bytes |
| コンパイル時間 | 754 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 148,760 KB |
| 最終ジャッジ日時 | 2024-07-26 19:48:39 |
| 合計ジャッジ時間 | 43,047 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 WA * 5 |
ソースコード
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)
yuusanlondon