MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / dfs

Function dfs

critical_connections_in_a_network_1192/solution.go:37–70  ·  view source on GitHub ↗
(node int, adjList map[int][]int, disc, low, parents []int, time int, critical [][]int)

Source from the content-addressed store, hash-verified

35}
36
37func dfs(node int, adjList map[int][]int, disc, low, parents []int, time int, critical [][]int) [][]int {
38 time++
39 disc[node] = time
40 low[node] = time
41
42 // for every node in the adjacency list, dfs
43 for _, edge := range adjList[node] {
44 parents[edge] = node
45
46 // if we have not seen the node over the edge before
47 if disc[edge] == -1 {
48 critical = dfs(edge, adjList, disc, low, parents, time, critical)
49
50 // compare the low values of both nodes to update the current
51 // nodes connectivity to the earliest node possible
52 low[node] = int(math.Min(float64(low[node]), float64(low[edge])))
53
54 // the edge is a bridge if the low of the edge is
55 // greater than the discovery time of the node
56 if low[edge] > disc[node] {
57 critical = append(critical, []int{node, edge})
58 }
59 }
60
61 // if we have seen the node before and it's not the parent
62 if edge != parents[node] {
63 // check if node is connected to any earlier nodes
64 // if so, set the low for node to the edge discovered the earliest
65 low[node] = int(math.Min(float64(disc[edge]), float64(low[node])))
66 }
67 }
68
69 return critical
70}

Callers 1

criticalConnectionsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected