Find a longest path between two nodes in an edge-weighted DAG.

Assignment

Your task is two write the following two functions, that each take the same three arguments: i) an integer representing the source node of a graph $$\mathcal{G}$$, ii) an integer representing the sink node of a graph $$\mathcal{G}$$ and iii) the location of a text file containing the description of an edge-weighted directed acyclic graph $$\mathcal{G}$$. The graph is represented by a modified adjacency list, with each line of the file containing the label (an integer) of a starting node, a space, the characters ->, another space, the label (an integer) of an ending node, a colon (:) and the weight (a positive integer) of the edge that connects the starting node with the ending node.

Example

In the following interactive session, we assume the text file data01.txt1 to be located in the current directory.

>>> longest_path_length(0, 4, 'data01.txt')
9

>>> longest_path(0, 4, 'data01.txt')
(0, 2, 3, 4)