Dag Longest Path Algorithm, , this question is a duplicate of the StackOverflow question Longest path in a DAG.