Since last 2 days,i\'m trying to find some logic for calculating longest path in graph.I know i can find it easily for DAGs and in general it is polynomial time algorithm.Formal
You could always just use a breadth first search (BFS) and, whenever you are adding an edge to the graph you have it's cost as the additive inverse (multiply it be -1). This way you are finding the 'shortest path' by using the longest edges. Because you're doing a scalar transform, you're not losing the ability to add within the group (which you do lose if you use the multiplicative inverse).