Home > Enterprise >  Topological sort for longest path in DAG?
Topological sort for longest path in DAG?

Time:12-11

I have an unweighted DAG, and I am trying to find the length of the longest path from any vertex in my graph. I found this: https://www.geeksforgeeks.org/find-longest-path-directed-acyclic-graph/

But it seems to be more focused on a weighted graph. How would I go about modifying that code to work for an unweighted graph so I could just find the integer value of the length of the longest path?

CodePudding user response:

How would I go about modifying that code to work for an unweighted graph so I could just find the integer value of the length of the longest path?

You can think of your graph as a weighted DAG, where each edge has a weight of 1 unit.

CodePudding user response:

Chanege this line

int getWeight() { return weight; }

to

int getWeight() { return 1; }
  • Related