-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDFST.cpp
More file actions
33 lines (30 loc) · 790 Bytes
/
DFST.cpp
File metadata and controls
33 lines (30 loc) · 790 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
struct DFST{
ll n, m;
vector<vector<int>> graph, tree, back_in, back_out;
vector<bool>vis;
vector<int> dep, par;
DFST(int _n, int _m){
n = _n, m = _m;
graph.resize(n+1);
tree.resize(n+1);
back_in.resize(n+1); back_out.resize(n+1);
par.resize(n+1); dep.assign(n+1, 0);
}
void add_edge(int u, int v){
graph[u].pb(v);
graph[v].pb(u);
}
void dfs(int node, int p){
par[node] = p;
dep[node] = dep[p]+1;
for(auto it: graph[node]){
if(!dep[it]){
tree[node].pb(it);
dfs(it, node);
}else if(dep[it] < dep[node]-1){
back_out[node].pb(it);
back_in[it].pb(node);
}
}
}
};