Given a Directed Graph. Find any Topological Sorting of that Graph.
The first line of input takes the number of test cases then T test cases follow . Each test case contains two lines. The first line of each test case contains two integers E and V representing no of edges and the number of vertices. Then in the next line are E pairs of integers u, v representing an edge from u to v in the graph.
For each test case output will be 1 if the topological sort is done correctly else it will be 0.
You don't need to read input or print anything. Your task is to complete the function topoSort() which takes the adjacency list of the Graph and the number of vertices (N) as inputs are returns an array consisting of a the vertices in Topological order. As there are multiple Topological orders possible, you may return any of them.
Expected Time Complexity: O(V + E).
Expected Auxiliary Space: O(V).
1 <= T <= 100
2 <= V <= 104
1 <= E <= (N*(N-1))/2
0 <= u, v <= N-1
Graph doesn't contain multiple edges, self loops and cycles.
Graph may be disconnected.
5 0 5 2 2 3 4 0 4 1 1 3
3 0 1 0 2 0
Testcase 1: The output 1 denotes that the order is valid. So, if you have implemented your function correctly, then output would be 1 for all test cases.
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.