Skip to content

Commit 153b2cc

Browse files
author
Hamid Gasmi
committed
Issue #87: solutions refactored
1 parent abe5893 commit 153b2cc

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

3-graph-algorithms/1_graph_decomposition/reachability.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def explore_dfs(self, u, v):
4141
return 1
4242

4343
self.visit(u)
44-
for i in range(len(self.adj[u])):
45-
if not self.isVisited(self.adj[u][i]):
46-
if self.explore_dfs(self.adj[u][i], v) == 1:
44+
for a in self.adj[u]:
45+
if not self.isVisited(a):
46+
if self.explore_dfs(a, v) == 1:
4747
return 1
4848

4949
return 0
@@ -65,8 +65,8 @@ def explore_bfs(self, u, v, q):
6565
return 1
6666
self.visit(u)
6767

68-
for i in range(len(self.adj[u])):
69-
self.enqueue(q, self.adj[u][i])
68+
for a in self.adj[u]:
69+
self.enqueue(q, a)
7070
return 0
7171

7272
def enqueue(self, q, v):
@@ -95,4 +95,4 @@ def reach(n, edges, u, v, solution):
9595
x, y = data[2 * m:]
9696
x, y = x - 1, y - 1
9797

98-
print(reach(n, edges, x, y, 2))
98+
print(reach(n, edges, x, y, 1))

3-graph-algorithms/1_graph_decomposition/reachability_parralel_bfs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def explore(self, u):
4747
if self.visit(u):
4848
return 1
4949

50-
for i in range(len(self.adj[u])):
51-
self.enqueue(self.adj[u][i])
50+
for a in self.adj[u]:
51+
self.enqueue(a)
5252

5353
return 0
5454

0 commit comments

Comments
 (0)