update visited matrix when complete current element