結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
momotaros300
|
| 提出日時 | 2019-10-26 17:53:34 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 2,587 ms / 4,000 ms |
| コード長 | 1,294 bytes |
| コンパイル時間 | 254 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 158,168 KB |
| 最終ジャッジ日時 | 2024-11-23 19:41:53 |
| 合計ジャッジ時間 | 23,782 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf=float('inf')
import heapq
def disktra(g,s):
n=len(g)
dist = [[inf]*2 for i in range(n)]
maxd=[0]*n
dist[s][0] = 0
dist[s][1]=0
hq=[]
heapq.heappush(hq,(dist[s][0],s,0))
while hq:
cost,u,used =heapq.heappop(hq)
if dist[u][used] < cost:
continue
if used ==0:
for v, c in g[u]:
# print(dist[v][1])
# print(v)
if dist[v][1] <= dist[u][0] :pass
else:
dist[v][1] = dist[u][0]
heapq.heappush(hq, (dist[v][1], v, 1))
for v,c in g[u]:
if dist[v][used] <= dist[u][used] +c:
continue
dist[v][used] = dist[u][used] + c
heapq.heappush(hq,(dist[v][used],v,used))
return dist
n,m=map(int,input().split())
abc=[]
G=[[]*n for i in range(n)]
G2=[[]*n for i in range(n)]
for i in range(m):
a,b,c=map(int,input().split())
a-=1;b-=1
G[a].append((b,c))
G[b].append((a,c))
d1=disktra(G,0)
# d2=disktra(G,0)
for i in range(n):
ans=min(d1[i][1]+d1[i][0],d1[i][0]+d1[i][1])
print(ans)
# print(d1)
# print(d2)
momotaros300