結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-25 23:27:48 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 3,047 ms / 4,000 ms |
| コード長 | 1,430 bytes |
| コンパイル時間 | 289 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 252,820 KB |
| 最終ジャッジ日時 | 2024-07-21 21:09:48 |
| 合計ジャッジ時間 | 31,218 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
class Dijkstra():
class Edge():
def __init__(self, _to, _cost):
self.to = _to
self.cost = _cost
def __init__(self, V):
self.G = [[] for i in range(V)]
self._E = 0
self._V = V
@property
def E(self):
return self._E
@property
def V(self):
return self._V
def add(self, _from, _to, _cost):
self.G[_from].append(self.Edge(_to, _cost))
self._E += 1
def shortest_path(self, s):
import heapq
que = []
d = [10**15] * self.V
d[s] = 0
heapq.heappush(que, (0, s))
while len(que) != 0:
cost, v = heapq.heappop(que)
if d[v] < cost: continue
for i in range(len(self.G[v])):
e = self.G[v][i]
if d[e.to] > d[v] + e.cost:
d[e.to] = d[v] + e.cost
heapq.heappush(que, (d[e.to], e.to))
return d
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
tour = Dijkstra(2*N)
for i in range(M):
a,b,c = map(int,input().split())
tour.add(2*a-2,2*b-2,c)
tour.add(2*a-1,2*b-1,c)
tour.add(2*a-1,2*b-2,0)
a,b = b,a
tour.add(2*a-2,2*b-2,c)
tour.add(2*a-1,2*b-1,c)
tour.add(2*a-1,2*b-2,0)
short_go = tour.shortest_path(1)
short_back = tour.shortest_path(0)
for i in range(N):
print(short_go[2*i]*(i>0)+short_back[2*i])