used a dict to keep track of edge weights