diff --git a/classicalAlgos/TopologicalSorting.cpp b/classicalAlgos/TopologicalSorting.cpp new file mode 100644 index 0000000..5f05124 --- /dev/null +++ b/classicalAlgos/TopologicalSorting.cpp @@ -0,0 +1,66 @@ +#include +using namespace std; +#define ll long long +#define pb push_back +#define ppb pop_back +#define sp <<" "<< +#define yes cout<<"YES"<>ppl; +typedef pairpl; +typedef vector vll; + +const int M = 1e9+7; +const int N = 1e5+5; +vectorg[N]; +vectorvis; +void toposort_dfs(int source, stack&st){ + vis[source] = true; + for(auto child:g[source]){ + if(vis[child]) continue; + toposort_dfs(child,st); + } + st.push(source); +} +void solve(int p) +{ + //taking input for the graph + int n,m; //m = number of nodes, m = number of edges + cin>>n>>m; + for(int i = 0;i>a>>b; + g[a].push_back(b); + } + vis.resize(n+1,false); + for(int i = 0;iv; + while(!st.emtpy()){ + v.push_back(st.top()); + st.pop(); + } + for(int i = 0;i>t; + int p = 1; + while (t--) + { + solve(p++); + } +} \ No newline at end of file