Friday, 20 February 2026

detetct cycle in directed graph uncompleted

  void dfs(int node,vector<int>&path){

    if(!path[node])path[node]=1;

    else {

        cout<<"cycle detected";

        return;

        

    }

    for(int x: adj[node]){

        dfs(x,path);

    }

    path[node]=0;

}

void checkcycle(){

    vector<int>path(v,0);

  dfs(0,path);

}

No comments:

Post a Comment

SDE floyd-warshall algorithm

 // User function template for C++ class Solution {   public:     void floydWarshall(vector<vector<int>> &dist) {         //...