1. You are given a directed acyclic graph. The vertices represent tasks and edges represent
dependencies between tasks.
2. You are required to find and print the order in which tasks could be done. The task that should be
done at last should be printed first and the task which should be done first should be printed last.
This is called topological sort. Check out the question video for details.
Topological sort -> A permutation of vertices for a directed acyclic graph is called topological sort if
for all directed edges uv, u appears before v in the graph
Note -> For output, check the sample output and question video.Input Format
Input has been managed for you
Output Format
Check the sample output
Constraints
None
Notice
Try First, Check Solution later
1. You should first read the question and watch the question video.2. Think of a solution approach, then try and submit the question on editor tab.3. We strongly advise you to watch the solution video for prescribed approach.Example
Input
7 7 0 1 1 2 2 3 0 3 4 5 5 6 4 6
Output
4 5 6 0 1 2 3