Given a directed graph and a proposed ordering of its vertices, return true if the ordering is a valid topological order. Pattern focus: Kahn Topological Order. This is a strong way to test whether the dependency relation is respected.
n = number of vertices, edges = directed edge list, order = proposed vertex order
true if the order is a valid topological ordering
Example 1:
Input:
n = 4 edges = [[0,1],[0,2],[1,3],[2,3]] order = [0,1,2,3]
Output:
true
Explanation:
Every edge points from an earlier vertex to a later vertex.
Example 2:
Input:
n = 4 edges = [[0,1],[0,2],[1,3],[2,3]] order = [0,2,1,3]
Output:
true
Explanation:
This order also respects all dependencies.
Example 3:
Input:
n = 3 edges = [[0,1],[1,2]] order = [1,0,2]
Output:
false
Explanation:
Vertex 0 must appear before vertex 1.