def dijkstra_path(dijkstra_result, source, target):
    """Constructs a path from a distance map returned by Dijkstra's algorithm.

    Args:
        dijkstra_result: Distance map from Dijkstra's algorithm.
        source: Vertex to start path from.
        target: Vertex to end the path.

    Returns:
        List of vertices covering path from source to target, both ends
        included. If target vertex is not reachable from source then None
        is returned.
    """
    result = [target]
    while True:
        if target is None:
            return None

        if target == source:
            return result[::-1]

        target = dijkstra_result[target][1]
        result.append(target)