677

 

729

Using Back Track Algorithm:

Using Next_permutation() method in C++

 

10364

 

307

 

624

 

193

 

539

Theory: This is an np-hard problem. As the degree of each node can be at most 3 so using dfs ,it can be solved. Follow the link

 

524