F1201-lecture1-180320-hamiltonian-path-and-cycle

easy
  1. You will be given an graph represented in form of ArrayList<ArrayList< edge >>, where edge
    is a user defined class  (a type) which contains three Integer data members:
	1st : v1 (denotes) vertex1.
	2nd : v2 (denotes) vertex2.
	3rd : wt (denotes the weight of edge b/w v1 and v2).
	
	(we constructed this representation of graph in 1st question)

Info:-  A Hamiltonian path is a path in graph that visits each vertex exactly once and A Hamiltonian cycle is a Hamiltonian path that is a cycle(The last vertex in path is neighbour of orignal source).
	
2. You are expected to write a function that checks if there exists hamiltonian paths then print them and then check if it is a hamiltonian cycle then return true else false(print cycle result after each and every path is printed ).
3. The graph is already constructed for you, so you do not need any input.
                               
                               

Input Format

Input is handled for you

Output Format

A String and a boolean (representing the hamiltonian path and boolean value represents the cycle).

Constraints

NA

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input

        
Output
0 -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 
0 -> 1 -> 2 -> 3 -> 4 -> 6 -> 5 -> 
2 -> 1 -> 0 -> 3 -> 4 -> 5 -> 6 -> 
2 -> 1 -> 0 -> 3 -> 4 -> 6 -> 5 -> 
5 -> 6 -> 4 -> 3 -> 0 -> 1 -> 2 -> 
5 -> 6 -> 4 -> 3 -> 2 -> 1 -> 0 -> 
6 -> 5 -> 4 -> 3 -> 0 -> 1 -> 2 -> 
6 -> 5 -> 4 -> 3 -> 2 -> 1 -> 0 -> 
false
Previous
F1201-lecture1-180320-kth-largest-path
Next
F1201-lecture1-180320-bfs-for-a-graphs

Related Questions