# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1083129 | Rishi_Jaiswal | Commuter Pass (JOI18_commuter_pass) | Cpython 3 | 2063 ms | 262144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import heapq
def dijkstra(graph, s, t):
visited = [False for _ in range(len(graph))]
costs = [float('inf') for _ in range(len(graph))]
paths = [[] for _ in range(len(graph))]
priority_queue = []
heapq.heappush(priority_queue, (0, s, [s]))
costs[s - 1] = 0
paths[s - 1] = [s]
while priority_queue:
current_cost, current_node, current_path = heapq.heappop(priority_queue)
if current_cost > costs[current_node - 1]:
continue
visited[current_node - 1] = True
for neighbour in graph[current_node]:
cost = current_cost + neighbour[1]
path = current_path + [neighbour[0]]
if cost < costs[neighbour[0] - 1]:
costs[neighbour[0] - 1] = cost
paths[neighbour[0] - 1].append(path)
heapq.heappush(priority_queue, (cost, neighbour[0], path))
elif cost == costs[neighbour[0] - 1]:
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |