結果
問題 | No.807 umg tours |
ユーザー |
![]() |
提出日時 | 2022-06-02 22:04:40 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,585 ms / 4,000 ms |
コード長 | 1,821 bytes |
コンパイル時間 | 353 ms |
コンパイル使用メモリ | 82,344 KB |
実行使用メモリ | 196,400 KB |
最終ジャッジ日時 | 2024-09-21 02:10:09 |
合計ジャッジ時間 | 17,203 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
import sysimport pypyjitimport itertoolsimport heapqimport mathfrom collections import deque, defaultdictimport bisectinput = sys.stdin.readlinesys.setrecursionlimit(10 ** 6)pypyjit.set_param('max_unroll_recursion=-1')def index_lt(a, x):'return largest index s.t. A[i] < x or -1 if it does not exist'return bisect.bisect_left(a, x) - 1def index_le(a, x):'return largest index s.t. A[i] <= x or -1 if it does not exist'return bisect.bisect_right(a, x) - 1def index_gt(a, x):'return smallest index s.t. A[i] > x or len(a) if it does not exist'return bisect.bisect_right(a, x)def index_ge(a, x):'return smallest index s.t. A[i] >= x or len(a) if it does not exist'return bisect.bisect_left(a, x)class Dijkstra:def __init__(self, N, E, inf=1 << 50):self.N = Nself.E = Eself.inf = infdef cost_from(self, s):C = [self.inf] * self.NC[2 * s] = 0C[2 * s + 1] = 0h = [(0, 2 * s)]visited = set()while len(h) > 0:_, v = heapq.heappop(h)if v in visited:continuevisited.add(v)for c, d in self.E[v]:if C[d] > C[v] + c:C[d] = C[v] + cheapq.heappush(h, (C[d], d))return CN, M = map(int, input().split())E = [[] for _ in range(2 * N)]for _ in range(M):a, b, c = map(int, input().split())a -= 1b -= 1a1, a0 = 2 * a, 2 * a + 1b1, b0 = 2 * b, 2 * b + 1E[a1].append((c, b1))E[a1].append((0, b0))E[a0].append((c, b0))E[b1].append((c, a1))E[b1].append((0, a0))E[b0].append((c, a0))solver = Dijkstra(2 * N, E)C = solver.cost_from(0)for i in range(N):print(C[2 * i] + C[2 * i + 1])