Medium Accuracy: 40.0% Submissions: 40030 Points: 4
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.