use crate::datastructures::AdjacencyMatrix;
pub mod approximate;
pub mod exact;
pub fn is_hamiltonian_cycle<A: AdjacencyMatrix>(path: &[usize], graph: &A) -> bool {
let num_vertices = graph.dim();
let mut used = vec![0; num_vertices];
for &u in path {
if u >= num_vertices {
return false;
}
used[u] += 1
}
let mut seen_vertex_twice = false;
used.into_iter().all(|num_occourances| {
if num_occourances == 2 {
if seen_vertex_twice {
false
} else {
seen_vertex_twice = true;
true
}
} else {
num_occourances == 1
}
})
}