結果
問題 | No.807 umg tours |
ユーザー | kurimupy |
提出日時 | 2020-06-15 17:03:51 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,233 ms / 4,000 ms |
コード長 | 1,829 bytes |
コンパイル時間 | 243 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 199,272 KB |
最終ジャッジ日時 | 2024-11-23 20:08:48 |
合計ジャッジ時間 | 22,471 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 63 ms
61,440 KB |
testcase_01 | AC | 73 ms
63,232 KB |
testcase_02 | AC | 83 ms
67,200 KB |
testcase_03 | AC | 65 ms
65,280 KB |
testcase_04 | AC | 54 ms
61,568 KB |
testcase_05 | AC | 56 ms
62,208 KB |
testcase_06 | AC | 67 ms
67,456 KB |
testcase_07 | AC | 61 ms
63,744 KB |
testcase_08 | AC | 44 ms
52,992 KB |
testcase_09 | AC | 45 ms
53,248 KB |
testcase_10 | AC | 45 ms
53,632 KB |
testcase_11 | AC | 1,250 ms
157,608 KB |
testcase_12 | AC | 1,229 ms
143,284 KB |
testcase_13 | AC | 1,716 ms
169,792 KB |
testcase_14 | AC | 807 ms
116,460 KB |
testcase_15 | AC | 660 ms
108,780 KB |
testcase_16 | AC | 1,725 ms
176,104 KB |
testcase_17 | AC | 2,144 ms
195,168 KB |
testcase_18 | AC | 2,145 ms
195,792 KB |
testcase_19 | AC | 2,062 ms
191,256 KB |
testcase_20 | AC | 1,030 ms
142,136 KB |
testcase_21 | AC | 1,114 ms
144,648 KB |
testcase_22 | AC | 502 ms
105,464 KB |
testcase_23 | AC | 451 ms
100,368 KB |
testcase_24 | AC | 869 ms
182,200 KB |
testcase_25 | AC | 2,233 ms
199,272 KB |
ソースコード
import sys import heapq input = sys.stdin.readline def dijkstra(s, graph): n = len(graph)-1 dist = [float("inf") for i in range(n+1)] dist[s] = 0 pq = [] heapq.heapify(pq) heapq.heappush(pq, (0, s)) while pq: mini_dis, node = heapq.heappop(pq) if dist[node] < mini_dis: continue for w, point in graph[node]: if dist[point] < w: continue newlen = dist[node]+w if newlen < dist[point]: heapq.heappush(pq, (newlen, point)) dist[point] = newlen return dist def s_dijkstra(s, graph): n = len(graph)-1 dist = [float("inf") for i in range(n+1)] dist[s] = 0 dist[s+N] = 0 pq = [] heapq.heapify(pq) heapq.heappush(pq, (0, s)) heapq.heappush(pq, (0, s+N)) while pq: mini_dis, node = heapq.heappop(pq) if dist[node] < mini_dis: continue for w, point in graph[node]: if dist[point] < w: continue newlen = dist[node]+w if newlen < dist[point]: heapq.heappush(pq, (newlen, point)) dist[point] = newlen return dist N, M = map(int, input().split()) graph = [[] for i in range(N+1)] special_graph = [[] for i in range(2*N+1)] for _ in range(M): a, b, c = map(int, input().split()) graph[a].append((c, b)) graph[b].append((c, a)) special_graph[a].append((0, b+N)) special_graph[a].append((c, b)) special_graph[a+N].append((c, b+N)) special_graph[b].append((c, a)) special_graph[b].append((0, a+N)) special_graph[b+N].append((c, a+N)) distance = dijkstra(1, graph) sub_distance = s_dijkstra(1, special_graph) for i in range(1, N+1): ans = distance[i]+sub_distance[i+N] print(ans)