Given a weighted acyclic directed graph (DAG) with
positive integer weights, and two nodes in the graph i, j
, find the longest path
from node i -> node j.
Input format:
line 1: [number of nodes N] [number of edges M]
line 2: i j
line 3 to M+2: [node1] [node2] [weight of edge node1->node2]
Example 1
Input: 4 5 0 3 0 1 10 0 2 20 1 3 30 2 3 15 0 3 60 Output: 60 Explanation: see the picture below; the longest path from node 0 to node 3 is 60.