Question: * * Code is still not working, please help * * I attahced my class code: class DFSTimeCounter: def _ _ init _ _ (

**Code is still not working, please help**
I attahced my class code:
class DFSTimeCounter:
def __init__(self):
self.count =0
def reset(self):
self.count =0
def increment(self):
self.count = self.count +1
def get(self):
return self.count
class UndirectedGraph:
def __init__(self, n):
self.n = n
self.adj_list =[ set() for i in range(self.n)]
def add_edge(self, i, j):
assert 0= i self.n
assert 0= j self.n
assert i != j
# Make sure to add edge from i to j
self.adj_list[i].add(j)
# Also add edge from j to i
self.adj_list[j].add(i)
# get a set of all vertices that
# are neighbors of the
# vertex i
def get_neighboring_vertices(self, i):
assert 0= i self.n
return self.adj_list[i]
def dfs_visit(self, i, dfs_timer, discovery_times, finish_times,
dfs_tree_parent, dfs_back_edges):
assert 0= i self.n
assert discovery_times[i]== None
assert finish_times[i]== None
discovery_times[i]= dfs_timer.get()
dfs_timer.increment()
for v in self.get_neighboring_vertices(i):
if discovery_times[v] is not None and finish_times[v] is None:
dfs_back_edges.append((i,v))
if discovery_times[v] is None:
dfs_tree_parent[v]= i
self.dfs_visit(v, dfs_timer, discovery_times, finish_times, dfs_tree_parent, dfs_back_edges)
finish_times[i]= dfs_timer.get()
dfs_timer.increment()
# Function: dfs_traverse_graph
# Traverse the entire graph.
def dfs_traverse_graph(self):
dfs_timer = DFSTimeCounter()
discovery_times =[None]*self.n
finish_times =[None]*self.n
dfs_tree_parents =[None]*self.n
dfs_back_edges =[]
for i in range(self.n):
if discovery_times[i]== None:
self.dfs_visit(i,dfs_timer, discovery_times, finish_times,
dfs_tree_parents, dfs_back_edges)
# Clean up the back edges so that if (i,j) is a back edge then j cannot
# be i's parent.
non_trivial_back_edges =[(i,j) for (i,j) in dfs_back_edges if dfs_tree_parents[i]!= j]
return (dfs_tree_parents, non_trivial_back_edges, discovery_times, finish_times)
* * Code is still not working, please help * * I

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!