結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
H20
|
| 提出日時 | 2021-05-02 14:38:55 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,531 bytes |
| コンパイル時間 | 1,602 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 367,308 KB |
| 最終ジャッジ日時 | 2024-07-20 23:34:54 |
| 合計ジャッジ時間 | 36,796 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 WA * 21 |
ソースコード
import collections
import heapq
class Dijkstra:
def __init__(self):
self.e = collections.defaultdict(list)
def add(self, u, v, d):
self.e[u].append([v, d])
self.e[v].append([u, d])
def delete(self, u, v):
self.e[u] = [_ for _ in self.e[u] if _[0] != v]
self.e[v] = [_ for _ in self.e[v] if _[0] != u]
def search(self, s):
"""
:param s: 始点
:return: 始点から各点までの最短経路
"""
d = collections.defaultdict(lambda: float('inf'))
d[s] = 0
q = []
heapq.heappush(q, (0, s))
v = collections.defaultdict(bool)
while len(q):
k, u = heapq.heappop(q)
if v[u]:
continue
v[u] = True
for uv, ud in self.e[u]:
if v[uv]:
continue
vd = k + ud
if d[uv] > vd:
d[uv] = vd
heapq.heappush(q, (vd, uv))
return d
N, M = map(int, input().split())
ABC = [list(map(int, input().split())) for i in range(M)]
graph1 = Dijkstra()#チケット使用しない
graph2 = Dijkstra()#チケット1枚使用(使用後をマイナスで表現)
for a,b,c in ABC:
graph1.add(a, b, c)
graph2.add(a, b, c)
graph2.add(a, -b, 0)
graph2.add(-a, -b, c)
g1 = graph1.search(1)
g2 = graph2.search(1)
print(0)#1から1は0、↓の計算でやると別な値が入るため
for i in range(2,N+1):
print(g1[i]+g2[-i])
H20