removes redundant edges also for undirected graphs