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);
}
// User function template for C++ class Solution { public: void floydWarshall(vector<vector<int>> &dist) { //...
No comments:
Post a Comment