結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
ayaoni
|
| 提出日時 | 2020-11-22 10:51:58 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,515 bytes |
| コンパイル時間 | 189 ms |
| コンパイル使用メモリ | 82,448 KB |
| 実行使用メモリ | 346,196 KB |
| 最終ジャッジ日時 | 2024-07-23 16:21:06 |
| 合計ジャッジ時間 | 38,919 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 WA * 20 TLE * 1 |
ソースコード
import sys,collections,heapq
def MI(): return map(int,sys.stdin.readline().rstrip().split())
class Dijkstra:
def __init__(self):
self.e = collections.defaultdict(list)
def add(self, u, v, d, directed=False):
if directed is False: # 無向グラフの場合
self.e[u].append([v, d])
self.e[v].append([u, d])
else: # 有向グラフの場合
self.e[u].append([v, 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): # sから各頂点までの最短距離
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 = MI()
Di = Dijkstra()
for _ in range(M):
a,b,c = MI()
Di.add((a,0),(b,0),c,directed=False)
Di.add((a,1),(b,1),c,directed=False)
Di.add((a,0),(b,1),0,directed=True)
Di.add((b,0),(a,1),c,directed=True)
dist = Di.search((1,0))
for i in range(1,N+1):
print(dist[(i,0)]+dist[(i,1)] if i != 1 else 0)
ayaoni