結果
問題 | No.807 umg tours |
ユーザー | OKCH3COOH |
提出日時 | 2019-11-13 20:46:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,444 ms / 4,000 ms |
コード長 | 1,233 bytes |
コンパイル時間 | 376 ms |
コンパイル使用メモリ | 82,768 KB |
実行使用メモリ | 157,972 KB |
最終ジャッジ日時 | 2024-05-03 00:07:17 |
合計ジャッジ時間 | 25,134 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 66 ms
68,480 KB |
testcase_01 | AC | 67 ms
69,632 KB |
testcase_02 | AC | 108 ms
76,664 KB |
testcase_03 | AC | 107 ms
76,544 KB |
testcase_04 | AC | 65 ms
67,456 KB |
testcase_05 | AC | 71 ms
70,528 KB |
testcase_06 | AC | 113 ms
76,800 KB |
testcase_07 | AC | 96 ms
76,300 KB |
testcase_08 | AC | 42 ms
52,992 KB |
testcase_09 | AC | 50 ms
60,800 KB |
testcase_10 | AC | 53 ms
61,952 KB |
testcase_11 | AC | 1,779 ms
141,688 KB |
testcase_12 | AC | 1,377 ms
120,740 KB |
testcase_13 | AC | 1,868 ms
139,476 KB |
testcase_14 | AC | 918 ms
103,216 KB |
testcase_15 | AC | 704 ms
96,464 KB |
testcase_16 | AC | 1,905 ms
139,908 KB |
testcase_17 | AC | 2,322 ms
155,376 KB |
testcase_18 | AC | 2,307 ms
153,988 KB |
testcase_19 | AC | 2,137 ms
147,880 KB |
testcase_20 | AC | 951 ms
113,400 KB |
testcase_21 | AC | 1,077 ms
116,500 KB |
testcase_22 | AC | 498 ms
92,496 KB |
testcase_23 | AC | 456 ms
89,840 KB |
testcase_24 | AC | 1,050 ms
143,956 KB |
testcase_25 | AC | 2,444 ms
157,972 KB |
ソースコード
from heapq import heappop, heappush N, M = map(int, input().split()) INF = float('inf') isOnePath = [False] * N edges = [[] for _ in range(N)] for _ in range(M): A, B, C = map(int, input().split()) A -= 1 B -= 1 edges[A].append((B, C)) edges[B].append((A, C)) minDist = [[INF] * N for _ in range(2)] que = [(0, (0, 0))] while que: dist, (now, height) = heappop(que) if minDist[height][now] <= dist: continue minDist[height][now] = dist if height == 0: for to, cost in edges[now]: if minDist[0][to] > dist + cost: heappush(que, (dist + cost, (to, 0))) if minDist[1][to] > dist: heappush(que, (dist, (to, 1))) else: for to, cost in edges[now]: if minDist[1][to] > dist + cost: heappush(que, (dist + cost, (to, 1))) reverseDist = [INF] * N que = [(0, 0)] while que: dist, now = heappop(que) if reverseDist[now] <= dist: continue reverseDist[now] = dist for to, cost in edges[now]: if reverseDist[to] > dist + cost: heappush(que, (dist + cost, to)) print(0) for i in range(1, N): ans = minDist[1][i] + reverseDist[i] print(ans)