diff --git a/Program's_Contributed_By_Contributors/C++ Programs/CycleDetectionBFS.cpp b/Program's_Contributed_By_Contributors/C++ Programs/CycleDetectionBFS.cpp new file mode 100644 index 0000000000..0ec63ac23e --- /dev/null +++ b/Program's_Contributed_By_Contributors/C++ Programs/CycleDetectionBFS.cpp @@ -0,0 +1,67 @@ +// Detecting cycle in the Directed Graph using BFS + + + +#include +using namespace std; + +class Solution { +public: + bool isCyclic(int N, vector adj[]) { + queue q; + vector indegree(N, 0); + for(int i = 0;i> t; + while(t--) + { + int V, E; + cin >> V >> E; + + vector adj[V]; + + for(int i = 0; i < E; i++) + { + int u, v; + cin >> u >> v; + adj[u].push_back(v); + } + + Solution obj; + cout << obj.isCyclic(V, adj) << "\n"; + } + + return 0; +}