your idea would reduce this problem to counting the number of distinct Hamiltonian paths in a undirected graph. Such a problem is generally hard (Hamiltonian path problem is NP-complete).