MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / dfs

Function dfs

CPP/graph_tree/articulation_Point.cpp:4–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2using namespace std;
3
4void dfs(unordered_set<int> &artpoints, vector<int> &time, vector<int> &lowest, vector<int> adj[],
5 vector<int> &visited, int node, int &currTime, int parent)
6{
7 visited[node] = 1;
8 time[node] = lowest[node] = currTime++;
9 for (int adjacent : adj[node])
10 {
11 if (adjacent == parent)
12 continue;
13
14 if (visited[adjacent] == 0)
15 {
16 dfs(artpoints, time, lowest, adj, visited, adjacent, currTime, node);
17 lowest[node] = min(lowest[node], lowest[adjacent]);
18
19 if (parent != -1 and lowest[adjacent] >= time[node])
20 artpoints.insert(node);
21 }
22
23 lowest[node] = min(lowest[node], lowest[adjacent]);
24 }
25 // specific case for starting point
26 if (parent == -1 and adj[node].size() > 1)
27 {
28 for (int adjacent : adj[node])
29 {
30 if (lowest[adjacent] > time[node])
31 {
32 artpoints.insert(node);
33 break;
34 }
35 }
36 }
37}
38
39int main()
40{

Callers 11

dfsMethod · 0.70
dfsOfGraphMethod · 0.70
mainFunction · 0.70
dfsMethod · 0.70
topoSortMethod · 0.70
dfsMethod · 0.50
closedIslandMethod · 0.50
dfsMethod · 0.50
floodFillMethod · 0.50
dfsMethod · 0.50
numIslandsMethod · 0.50

Calls 2

insertMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected