Fix neighbors logic for undirected graphs.