Find a longest path between two nodes in an edge-weighted DAG.
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.
Write a function longest_path_length that returns the length of a longest path in $$\mathcal{G}$$ between the given source and sink nodes.
Write a function longest_path that returns a longest path in $$\mathcal{G}$$ between the given source and sink nodes, given as a tuple of node labels. If multiple longest paths exist between the given source and sink nodes, the function may return any one.
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)