How to assign “levels” to vertices of an acyclic directed graph?

后端 未结 2 1607
生来不讨喜
生来不讨喜 2020-12-17 05:31

I have an acyclic directed graph. I would like to assign levels to each vertex in a manner that guarantees that if the edge (v1,v2) is in the graph, then level(v1) > level(

2条回答
  •  不知归路
    2020-12-17 06:10

    You could use a topological sort to assign a unique number to each vertex with the property that you want Similarly you could go through the nodes in topological order and assign max(parents) + 1

提交回复
热议问题