From ac07eed5cac2e9f69d430bcd83668b31a4243169 Mon Sep 17 00:00:00 2001 From: pandey2021 <84921465+pandey2021@users.noreply.github.com> Date: Sun, 15 Jan 2023 11:47:05 +0530 Subject: [PATCH] Add files via upload --- classicalAlgos/TopologicalSorting.cpp | 66 +++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 classicalAlgos/TopologicalSorting.cpp 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