-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBIGDFS.cpp
More file actions
42 lines (37 loc) · 750 Bytes
/
Copy pathBIGDFS.cpp
File metadata and controls
42 lines (37 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
using namespace std;
bool dfsx(int v,int e,vector<int>*g,bool*marked,bool*incycle){
marked[v] = true;
if(v==e)return true;
for(int x: g[v])
if(!marked[x])
if(dfs(x,e,g,marked,incycle)){
incycle[x] = true;
return true;
}
}
void dfsr(int s,int e,vector<int>*g,bool* marked,bool *incycle){
incycle[s] = true;
incycle[e] = true;
marked[s] = true;
for(int v : g[s]){
if(v!=e)
if(dfsx(v,e,g,marked,incycle))return;
}
}
void dfs(int x,vector<int>*g,
bool*marked,int prev,bool*incycle)
{
mark[x] = true;
for(int i=0;i<g[x].size();i++){
int v = g[x][i];
if(marked[v]){
if(v!=prev){
dfsr(x,v,g,(bool*)
memset(n*sizeof(bool)),incycle);
}
}else {
dfs(v,g,marked,x,incycle);
}
}
}