結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
sasa8uyauya
|
| 提出日時 | 2024-09-18 19:01:27 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 2,177 ms / 4,000 ms |
| コード長 | 734 bytes |
| コンパイル時間 | 404 ms |
| コンパイル使用メモリ | 82,204 KB |
| 実行使用メモリ | 189,484 KB |
| 最終ジャッジ日時 | 2024-09-18 19:01:53 |
| 合計ジャッジ時間 | 23,937 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
n,m=map(int,input().split())
e=[[] for i in range(n*2)]
for i in range(m):
a,b,c=map(int,input().split())
a-=1
b-=1
e[a]+=[(b,c)]
e[a]+=[(b+n,0)]
e[a+n]+=[(b+n,c)]
e[b]+=[(a,c)]
e[b]+=[(a+n,0)]
e[b+n]+=[(a+n,c)]
X=10**20
from heapq import heappush,heappop
v=[X]*n*2
s=0
v[s]=0
q=[(v[s],s)]
while len(q)>0:
sc,sp=heappop(q)
if sc>v[sp]:
continue
for tp,tc in e[sp]:
if v[tp]>sc+tc:
v[tp]=sc+tc
heappush(q,(v[tp],tp))
v1=v.copy()
v=[X]*n*2
s=0+n
v[s]=0
q=[(v[s],s)]
while len(q)>0:
sc,sp=heappop(q)
if sc>v[sp]:
continue
for tp,tc in e[sp]:
if v[tp]>sc+tc:
v[tp]=sc+tc
heappush(q,(v[tp],tp))
v2=v.copy()
for i in range(n):
print(min(v1[i]+v2[i+n],v1[i+n]+v2[i+n]))
sasa8uyauya