human
Give me a code to count total ways to reach destination from source in an undirected Graph and the other steps required given the following:
Count total ways to reach destination from source in an undirected Graph | Utility Function to count total ways.
Base condition When reach to the destination.
Make vertex visited.
Recursive function , for count ways.
Backtracking Make vertex unvisited.
Return total ways.
Function to count total ways to reach destination.
Loop to make all vertex unvisited , Initially.
Make source visited.
Print total ways"
Solution in Python:
assistant
#Here is code to count total ways to reach destination from source in an undirected Graph and the other steps required.
 def countWays ( mtrx , vrtx , i , dest , visited ) :
	if ( i == dest ) :
		return 1
	total = 0
	for j in range ( vrtx ) :
		if ( mtrx [ i ] [ j ] == 1 and not visited [ j ] ) :
			visited [ j ] = True ;
			total += countWays ( mtrx , vrtx , j , dest , visited ) ;
			visited [ j ] = False ;
	return total
def totalWays ( mtrx , vrtx , src , dest ) :
	visited = [ False ] * vrtx
	for i in range ( vrtx ) :
		visited [ i ] = False
	visited [ src ] = True ;
	return countWays ( mtrx , vrtx , src , dest , visited )
print ( totalWays ( mtrx , vrtx , src - 1 , dest - 1 ) )