結果
問題 | No.807 umg tours |
ユーザー | OKCH3COOH |
提出日時 | 2019-11-13 20:46:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,888 ms / 4,000 ms |
コード長 | 1,233 bytes |
コンパイル時間 | 241 ms |
コンパイル使用メモリ | 82,196 KB |
実行使用メモリ | 158,232 KB |
最終ジャッジ日時 | 2024-11-23 19:45:42 |
合計ジャッジ時間 | 19,934 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 64 ms
68,464 KB |
testcase_01 | AC | 72 ms
71,400 KB |
testcase_02 | AC | 107 ms
76,796 KB |
testcase_03 | AC | 98 ms
76,100 KB |
testcase_04 | AC | 64 ms
68,108 KB |
testcase_05 | AC | 69 ms
70,848 KB |
testcase_06 | AC | 111 ms
76,540 KB |
testcase_07 | AC | 94 ms
76,300 KB |
testcase_08 | AC | 41 ms
54,184 KB |
testcase_09 | AC | 46 ms
60,824 KB |
testcase_10 | AC | 49 ms
62,560 KB |
testcase_11 | AC | 1,338 ms
141,348 KB |
testcase_12 | AC | 1,105 ms
120,740 KB |
testcase_13 | AC | 1,438 ms
139,648 KB |
testcase_14 | AC | 754 ms
103,472 KB |
testcase_15 | AC | 563 ms
96,328 KB |
testcase_16 | AC | 1,485 ms
139,648 KB |
testcase_17 | AC | 1,802 ms
155,632 KB |
testcase_18 | AC | 1,771 ms
154,112 KB |
testcase_19 | AC | 1,685 ms
148,128 KB |
testcase_20 | AC | 782 ms
112,888 KB |
testcase_21 | AC | 890 ms
116,112 KB |
testcase_22 | AC | 402 ms
92,236 KB |
testcase_23 | AC | 380 ms
89,588 KB |
testcase_24 | AC | 917 ms
143,448 KB |
testcase_25 | AC | 1,888 ms
158,232 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)