def _reconstruct_path(source_node, target_node, scanned_nodes):
    """
    Reconstruct a path from the scanned table.

    It returns an edge sequence along the path and the path cost (sum
    of edges cost).
    """
    path, path_cost = [], 0
    node = target_node
    while node is not None:
        edge = scanned_nodes[node]
        path.append(edge)
        path_cost += edge.cost
        node = edge.start_node

    # Pop out the dummy edge ending with the source node
    if path:
        assert path[-1] == (None, source_node, 0)
        path.pop()

    return path, path_cost