@not_implemented_for('undirected')
@not_implemented_for('multigraph')
def hamiltonian_path(G):
 if (len(G) == 0):
  return []
 if (len(G) == 1):
  return [arbitrary_element(G)]
 v = arbitrary_element(G)
 hampath = hamiltonian_path(G.subgraph((set(G) - {v})))
 index = index_satisfying(hampath, (lambda u: (v not in G[u])))
 hampath.insert(index, v)
 return hampath

@ not_implemented_for ( 'undirected' ) @ not_implemented_for ( 'multigraph' ) def hamiltonian_path ( G ) : if ( len ( G ) == 0 ) : return [ ] if ( len ( G ) == 1 ) : return [ arbitrary_element ( G ) ] v = arbitrary_element ( G ) hampath = hamiltonian_path ( G . subgraph ( ( set ( G ) - { v } ) ) ) index = index_satisfying ( hampath , ( lambda u : ( v not in G [ u ] ) ) ) hampath . insert ( index , v ) return hampath
returns a hamiltonian path in the given tournament graph .